diff options
| author | Marc Florisson | 2015-02-03 12:26:37 +0100 |
|---|---|---|
| committer | Marc Florisson | 2015-02-03 12:26:37 +0100 |
| commit | a98cf1bdae71922512abb284429c96777d01db18 (patch) | |
| tree | e9f76cfa66b50e48b9061a1d3b3e34022e9e87a2 /lib | |
| parent | 04148815395986714ac6c1f98abcc23744cb97eb (diff) | |
| download | chouette-core-a98cf1bdae71922512abb284429c96777d01db18.tar.bz2 | |
first refactor to add rule parameter set to organisation
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ninoxe_extension/hub/company_restrictions.rb | 20 | ||||
| -rw-r--r-- | lib/ninoxe_extension/hub/connection_link_restrictions.rb | 16 | ||||
| -rw-r--r-- | lib/ninoxe_extension/hub/group_of_line_restrictions.rb | 21 | ||||
| -rw-r--r-- | lib/ninoxe_extension/hub/journey_pattern_restrictions.rb | 20 | ||||
| -rw-r--r-- | lib/ninoxe_extension/hub/line_restrictions.rb | 25 | ||||
| -rw-r--r-- | lib/ninoxe_extension/hub/network_restrictions.rb | 20 | ||||
| -rw-r--r-- | lib/ninoxe_extension/hub/objectid_restrictions.rb | 22 | ||||
| -rw-r--r-- | lib/ninoxe_extension/hub/route_restrictions.rb | 10 | ||||
| -rw-r--r-- | lib/ninoxe_extension/hub/stop_area_restrictions.rb | 53 | ||||
| -rw-r--r-- | lib/ninoxe_extension/hub/time_table_restrictions.rb | 18 | ||||
| -rw-r--r-- | lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb | 16 |
11 files changed, 238 insertions, 3 deletions
diff --git a/lib/ninoxe_extension/hub/company_restrictions.rb b/lib/ninoxe_extension/hub/company_restrictions.rb new file mode 100644 index 000000000..780e0e4d9 --- /dev/null +++ b/lib/ninoxe_extension/hub/company_restrictions.rb @@ -0,0 +1,20 @@ +module NinoxeExtension::Hub + module CompanyRestrictions + extend ActiveSupport::Concern + + included do + include ObjectidRestrictions + + with_options if: :hub_restricted? do |g| + # HUB-7 + g.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,3}$} + # HUB-8 + g.validates_format_of :name, :with => %r{^[\w]{1,75}$} + # HUB-9 + g.validates_format_of :registration_number, :with => %r{^[\d]{1,8}$} + g.validates_uniqueness_of :registration_number + end + end + end +end + diff --git a/lib/ninoxe_extension/hub/connection_link_restrictions.rb b/lib/ninoxe_extension/hub/connection_link_restrictions.rb new file mode 100644 index 000000000..bf433379b --- /dev/null +++ b/lib/ninoxe_extension/hub/connection_link_restrictions.rb @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub + module ConnectionLinkRestrictions + extend ActiveSupport::Concern + + included do + include ObjectidRestrictions + + with_options if: :hub_restricted? do |jp| + # HUB-34 + jp.validates :link_distance, :numericality => { :max => 10000.0 } + end + end + end +end + diff --git a/lib/ninoxe_extension/hub/group_of_line_restrictions.rb b/lib/ninoxe_extension/hub/group_of_line_restrictions.rb new file mode 100644 index 000000000..13688376f --- /dev/null +++ b/lib/ninoxe_extension/hub/group_of_line_restrictions.rb @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub + module GroupOfLineRestrictions + extend ActiveSupport::Concern + + included do + include ObjectidRestrictions + + with_options if: :hub_restricted? do |g| + # HUB-11 + g.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,6}$} + # HUB-12 + g.validates_format_of :name, :with => %r{^[\w]{1,75}$} + # HUB-13 + g.validates_format_of :registration_number, :with => %r{^[\d]{1,8}$} + g.validates_uniqueness_of :registration_number + end + end + end +end + diff --git a/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb b/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb new file mode 100644 index 000000000..2726c563a --- /dev/null +++ b/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub + module JourneyPatternRestrictions + extend ActiveSupport::Concern + + included do + include ObjectidRestrictions + + with_options if: :hub_restricted? do |jp| + # HUB-39 + jp.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,30}$} + # HUB-40 + jp.validates :registration_number, :numericality => { :less_than => 10 ** 8 } + # HUB-41 + jp.validates_format_of :name, :with => %r{^[\w]{0,75}$} + end + end + end +end + diff --git a/lib/ninoxe_extension/hub/line_restrictions.rb b/lib/ninoxe_extension/hub/line_restrictions.rb new file mode 100644 index 000000000..119ab07b6 --- /dev/null +++ b/lib/ninoxe_extension/hub/line_restrictions.rb @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub + module LineRestrictions + extend ActiveSupport::Concern + + + included do + include ObjectidRestrictions + + with_options if: :hub_restricted? do |l| + # HUB-15 + l.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,14}$} + # HUB-16 + l.validates_format_of :number, :with => %r{^[\w]{1,6}$} + # HUB-17 + l.validates_format_of :name, :with => %r{^[\w]{0,75}$} + # HUB-21 + l.validates :registration_number, :numericality => { :less_than => 10 ** 8 } + # HUB-22 + l.validates_uniqueness_of :name, :allow_blank => true + end + end + end +end + diff --git a/lib/ninoxe_extension/hub/network_restrictions.rb b/lib/ninoxe_extension/hub/network_restrictions.rb new file mode 100644 index 000000000..b2e8d4be5 --- /dev/null +++ b/lib/ninoxe_extension/hub/network_restrictions.rb @@ -0,0 +1,20 @@ +module NinoxeExtension::Hub + module NetworkRestrictions + extend ActiveSupport::Concern + + included do + include ObjectidRestrictions + + with_options if: :hub_restricted? do |g| + # HUB-3 + g.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,3}$} + # HUB-4 + g.validates_format_of :name, :with => %r{^[\w]{1,75}$} + # HUB-5 + g.validates_format_of :registration_number, :with => %r{^[\d]{1,8}$} + g.validates_uniqueness_of :registration_number + end + end + end +end + diff --git a/lib/ninoxe_extension/hub/objectid_restrictions.rb b/lib/ninoxe_extension/hub/objectid_restrictions.rb new file mode 100644 index 000000000..675994359 --- /dev/null +++ b/lib/ninoxe_extension/hub/objectid_restrictions.rb @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub::ObjectidRestrictions + extend ActiveSupport::Concern + + included do + # HUB 1 + validate :third_part_objectid_uniqueness + + def third_part_objectid + self.objectid.match(/:(\w+)$/)[1] + end + def third_part_objectid_uniqueness + return unless hub_restricted? + + return true unless third_part_objectid + likes = Chouette::Line.where( "objectid LIKE ?", "%:#{self.third_part_objectid}" ) + likes.size.zero? || ( likes.size==1 && likes.first.id==self.id) + end + + end +end + diff --git a/lib/ninoxe_extension/hub/route_restrictions.rb b/lib/ninoxe_extension/hub/route_restrictions.rb index c6c403796..6b996ec3d 100644 --- a/lib/ninoxe_extension/hub/route_restrictions.rb +++ b/lib/ninoxe_extension/hub/route_restrictions.rb @@ -1,25 +1,29 @@ # -*- coding: utf-8 -*- -module NinoxeExtension::Hub::RouteRestrictions +module NinoxeExtension::Hub + module RouteRestrictions extend ActiveSupport::Concern included do + include ObjectidRestrictions validate :max_instance_limitation, :wayback_code_limitation + # HUB-37 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 + # HUB-37 def max_instance_limitation return unless hub_restricted? errors.add( :flash, "2 routes max") end + # HUB-38 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 end diff --git a/lib/ninoxe_extension/hub/stop_area_restrictions.rb b/lib/ninoxe_extension/hub/stop_area_restrictions.rb new file mode 100644 index 000000000..f09510cc4 --- /dev/null +++ b/lib/ninoxe_extension/hub/stop_area_restrictions.rb @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub + module StopAreaRestrictions + extend ActiveSupport::Concern + + included do + #include ObjectidRestrictions + def physical? + self.area_type=="BoardingPosition" || self.area_type=="Quay" + end + def commercial? + self.area_type=="CommercialStopPoint" + end + def self.physical_hub_restricted? + Proc.new { |s| s.hub_restricted? && s.commercial?} + end + def self.commercial_hub_restricted? + Proc.new { |s| s.hub_restricted? && s.physical?} + end + def self.commercial_and_physical_hub_restricted? + physical_hub_restricted? || commercial_hub_restricted? + end + + + with_options if: commercial_and_physical_hub_restricted? do |sa| + # HUB-23 + sa.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,12}$} + sa.validates_format_of :name, :with => %r{^[\w]{1,75}$} + end + with_options if: commercial_hub_restricted? do |sa| + # HUB-24 + validates_format_of :nearest_topic_name, :with => %r{^[\w]{0,255}$} + end + + with_options if: physical_hub_restricted? do |sa| + # HUB-25 + sa.validates_format_of :nearest_topic_name, :with => %r{^[\w]{0,60}$} + # HUB-28 + sa.validates_presence_of :longitude + sa.validates_presence_of :latitude + # HUB-29 + sa.validates_format_of :city_name, :with => %r{^[\w]{1,80}$} + # HUB-30 + sa.validates_format_of :zip_code, :with => %r{^[\d]{5}$} + # HUB-31 + sa.validates_format_of :comment, :with => %r{^[\w]{0,255}$} + # HUB-32 + sa.validates_format_of :registration_number, :with => %r{^[\w]{1,8}$}, :allow_blank => true, :allow_nil => true + end + end + end +end + diff --git a/lib/ninoxe_extension/hub/time_table_restrictions.rb b/lib/ninoxe_extension/hub/time_table_restrictions.rb new file mode 100644 index 000000000..6f2984dda --- /dev/null +++ b/lib/ninoxe_extension/hub/time_table_restrictions.rb @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub + module TimeTableRestrictions + extend ActiveSupport::Concern + + included do + include ObjectidRestrictions + + with_options if: :hub_restricted? do |jp| + # HUB-44 + jp.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,6}$} + # HUB-45 + jp.validates_format_of :comment, :with => %r{^[\w]{0,75}$} + end + end + end +end + diff --git a/lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb b/lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb new file mode 100644 index 000000000..81a023dca --- /dev/null +++ b/lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub + module VehicleJourneyRestrictions + extend ActiveSupport::Concern + + included do + include ObjectidRestrictions + + # HUB-42 + with_options if: :hub_restricted? do |jp| + jp.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,8}$} + end + end + end +end + |
