diff options
| author | Marc Florisson | 2015-01-26 10:00:13 +0100 |
|---|---|---|
| committer | Marc Florisson | 2015-01-26 10:00:13 +0100 |
| commit | 657966f57ab15234effcc56d58ff49dace885576 (patch) | |
| tree | eb03fb97d9138b9f7feb2a81e7768238410d793b /lib | |
| parent | c6f7d75a1c41db2406510b9c33c86506ab190bc9 (diff) | |
| download | chouette-core-657966f57ab15234effcc56d58ff49dace885576.tar.bz2 | |
add restrictions specific to Hub
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ninoxe_extension/hub/route_restrictions.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/ninoxe_extension/hub/route_restrictions.rb b/lib/ninoxe_extension/hub/route_restrictions.rb new file mode 100644 index 000000000..c6c403796 --- /dev/null +++ b/lib/ninoxe_extension/hub/route_restrictions.rb @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub::RouteRestrictions + extend ActiveSupport::Concern + + included do + validate :max_instance_limitation, :wayback_code_limitation + + def wayback_code_limitation + return unless hub_restricted? + errors.add( :wayback_code, "déjà pris!") if line.routes.reject {|r| r.id==id}.map(&:wayback_code).include?( wayback_code) + end + + def max_instance_limitation + return unless hub_restricted? + errors.add( :flash, "2 routes max") + end + + with_options if: :hub_restricted? do |route| + route.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,8}$} + #admin.validates :password, length: { minimum: 10 } + #admin.validates :email, presence: true + end + end +end + |
