aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorXinhui2016-02-22 15:31:31 +0100
committerXinhui2016-02-22 15:31:31 +0100
commit0a1ffa22d97160797d2c96debbc99b31792a40c5 (patch)
tree7cea5119ddf42cbfe8d1e52c6d28096979830cd4 /lib
parentd49f47b4ac1db2cd88b96d830772bb7773924601 (diff)
downloadchouette-core-0a1ffa22d97160797d2c96debbc99b31792a40c5.tar.bz2
Merge NinoxeExtension concerns
Diffstat (limited to 'lib')
-rw-r--r--lib/ninoxe_extension/hub/company_restrictions.rb28
-rw-r--r--lib/ninoxe_extension/hub/connection_link_restrictions.rb16
-rw-r--r--lib/ninoxe_extension/hub/group_of_line_restrictions.rb29
-rw-r--r--lib/ninoxe_extension/hub/journey_pattern_restrictions.rb24
-rw-r--r--lib/ninoxe_extension/hub/line_restrictions.rb33
-rw-r--r--lib/ninoxe_extension/hub/network_restrictions.rb28
-rw-r--r--lib/ninoxe_extension/hub/objectid_restrictions.rb29
-rw-r--r--lib/ninoxe_extension/hub/route_restrictions.rb29
-rw-r--r--lib/ninoxe_extension/hub/stop_area_restrictions.rb67
-rw-r--r--lib/ninoxe_extension/hub/time_table_restrictions.rb22
-rw-r--r--lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb19
-rw-r--r--lib/ninoxe_extension/projection_fields.rb63
12 files changed, 0 insertions, 387 deletions
diff --git a/lib/ninoxe_extension/hub/company_restrictions.rb b/lib/ninoxe_extension/hub/company_restrictions.rb
deleted file mode 100644
index ee194a046..000000000
--- a/lib/ninoxe_extension/hub/company_restrictions.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-module NinoxeExtension::Hub
- module CompanyRestrictions
- extend ActiveSupport::Concern
-
- included do
- include ObjectidRestrictions
-
- with_options if: :hub_restricted? do |g|
- # HUB-7
- g.validate :specific_objectid
- # HUB-8
- #g.validates_length_of :name, :minimum => 1, :maximum => 75
- g.validates :name, length: { in: 1..75 }
- # HUB-9
- #g.validates_format_of :registration_number, :with => %r{\A[\d]{1,8}\z}
- #g.validates_uniqueness_of :registration_number
- g.validates :registration_number,
- uniqueness: true,
- length: { in: 1..8 },
- numericality: { only_integer: true }
- end
- end
- def specific_objectid
- validate_specific_objectid(3)
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/hub/connection_link_restrictions.rb b/lib/ninoxe_extension/hub/connection_link_restrictions.rb
deleted file mode 100644
index 6d4c3046f..000000000
--- a/lib/ninoxe_extension/hub/connection_link_restrictions.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# -*- coding: utf-8 -*-
-module NinoxeExtension::Hub
- module ConnectionLinkRestrictions
- extend ActiveSupport::Concern
-
- included do
- include ObjectidRestrictions
-
- with_options if: :hub_restricted? do |cl|
- # HUB-34
- cl.validates :link_distance, numericality: { less_than_or_equal_to: 10000.to_f }
- 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
deleted file mode 100644
index 26e5c5d5c..000000000
--- a/lib/ninoxe_extension/hub/group_of_line_restrictions.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# -*- 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.validate :specific_objectid
- # HUB-12
- #g.validates_length_of :name, :minimum => 1, :maximum => 75
- g.validates :name, length: { in: 1..75 }
- # HUB-13
- #g.validates_format_of :registration_number, :with => %r{\A[\d]{1,8}\z}
- #g.validates_uniqueness_of :registration_number
- g.validates :registration_number,
- uniqueness: true,
- numericality: { only_integer: true },
- length: { in: 1..8 }
- end
- end
- def specific_objectid
- validate_specific_objectid(6)
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb b/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb
deleted file mode 100644
index f3ec2cdbd..000000000
--- a/lib/ninoxe_extension/hub/journey_pattern_restrictions.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# -*- 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.validate :specific_objectid
- # HUB-40
- jp.validates :registration_number, numericality: { less_than: 10 ** 8 }
- # HUB-41
- #jp.validates_length_of :name, :maximum => 75, :allow_blank => true, :allow_nil => true
- jp.validates :name, length: { maximum: 75 }, allow_blank: true
- end
- end
- def specific_objectid
- validate_specific_objectid( 30)
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/hub/line_restrictions.rb b/lib/ninoxe_extension/hub/line_restrictions.rb
deleted file mode 100644
index bdae3d77c..000000000
--- a/lib/ninoxe_extension/hub/line_restrictions.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-# -*- 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{\A\w+:\w+:[\w]{1,14}\z}
- l.validate :specific_objectid
- # HUB-16
- #l.validates_format_of :number, :with => %r{\A[\w]{1,6}\z}
- l.validates :number, length: { in: 1..6 }, format: { with: /\A[\w]+\z/ }
- # HUB-17 & HUB-22
- #l.validates_length_of :name, :maximum => 75
- l.validates :name, length: { maximum: 75 }, uniqueness: true, allow_blank: true
- # HUB-21
- #l.validates :registration_number, :numericality => { :less_than => 10 ** 8 }
- l.validates :registration_number, presence: true, numericality: { less_than: 10 ** 8 }
- # HUB-22
- #l.validates_uniqueness_of :name, :allow_blank => true
- end
- end
-
- def specific_objectid
- validate_specific_objectid( 14)
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/hub/network_restrictions.rb b/lib/ninoxe_extension/hub/network_restrictions.rb
deleted file mode 100644
index deba1f75e..000000000
--- a/lib/ninoxe_extension/hub/network_restrictions.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-module NinoxeExtension::Hub
- module NetworkRestrictions
- extend ActiveSupport::Concern
-
- included do
- include ObjectidRestrictions
-
- with_options if: :hub_restricted? do |n|
- # HUB-3
- n.validate :specific_objectid
- # HUB-4
- #n.validates_length_of :name, :minimum => 1, :maximum => 75
- n.validates :name, length: { in: 1..75 }
- # HUB-5
- #n.validates_format_of :registration_number, :with => %r{\A[\d]{1,8}\z}
- #n.validates_uniqueness_of :registration_number
- n.validates :registration_number,
- uniqueness: true,
- numericality: { only_integer: true },
- length: { in: 1..8 }
- end
- end
- def specific_objectid
- validate_specific_objectid( 3)
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/hub/objectid_restrictions.rb b/lib/ninoxe_extension/hub/objectid_restrictions.rb
deleted file mode 100644
index 1a71b9e62..000000000
--- a/lib/ninoxe_extension/hub/objectid_restrictions.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# -*- coding: utf-8 -*-
-module NinoxeExtension::Hub::ObjectidRestrictions
- extend ActiveSupport::Concern
-
- included do
- # HUB 1
- validate :third_part_objectid_uniqueness
- end
-
- def validate_specific_objectid( size_max )
- #errors.add( :objectid, I18n.t('hub.invalid')) if ( %r{\A\w+:\w+:\w+\z}).match( self.objectid).nil?
-
- if third_part_objectid.nil? || ( !third_part_objectid.include?( "_pending_" ) && third_part_objectid.size > size_max)
- errors.add( :objectid, I18n.t('hub.invalid'))
- end
- end
- def third_part_objectid
- return nil if ( %r{\A\w+:\w+:[0-9A-Za-z_-]+\z}).match( self.objectid).nil?
- self.objectid.match(/:([0-9A-Za-z_-]+)\z/)[1]
- end
- def third_part_objectid_uniqueness
- return unless hub_restricted?
-
- return true unless third_part_objectid
- likes = self.class.where( "objectid LIKE ?", "%:#{self.third_part_objectid}" )
- likes.size.zero? || ( likes.size==1 && likes.first.id==self.id)
- end
-end
-
diff --git a/lib/ninoxe_extension/hub/route_restrictions.rb b/lib/ninoxe_extension/hub/route_restrictions.rb
deleted file mode 100644
index 6304d3559..000000000
--- a/lib/ninoxe_extension/hub/route_restrictions.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# -*- coding: utf-8 -*-
-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, I18n.t('hub.routes.wayback_code_exclusive')) 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, I18n.t('hub.routes.max_by_line')) if 2 < line.routes.size
- end
-
- # HUB-38
- with_options if: :hub_restricted? do |route|
- route.validates_format_of :objectid, :with => %r{\A\w+:\w+:([\w]{1,8}|__pending_id__\d+)\z}
- end
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/hub/stop_area_restrictions.rb b/lib/ninoxe_extension/hub/stop_area_restrictions.rb
deleted file mode 100644
index 17df9dba1..000000000
--- a/lib/ninoxe_extension/hub/stop_area_restrictions.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-# -*- coding: utf-8 -*-
-module NinoxeExtension::Hub
- module StopAreaRestrictions
- extend ActiveSupport::Concern
-
- def physical?
- self.area_type=="BoardingPosition" || self.area_type=="Quay"
- end
- def commercial?
- self.area_type=="CommercialStopPoint"
- end
- def physical_hub_restricted?
- hub_restricted? && physical?
- end
- def commercial_hub_restricted?
- hub_restricted? && commercial?
- end
- def commercial_and_physical_hub_restricted?
- physical_hub_restricted? || commercial_hub_restricted?
- end
- # def specific_objectid
- # validate_specific_objectid( 12)
- # end
-
- included do
- include ObjectidRestrictions
-
-
- with_options if: :commercial_and_physical_hub_restricted? do |sa|
- # HUB-23
- sa.validate :specific_objectid
- #sa.validates_length_of :name, :minimum => 1, :maximum => 75
- sa.validates :name, length: { in: 1..75 }
- end
-
- with_options if: :commercial_hub_restricted? do |sa|
- # HUB-24
- #sa.validates_length_of :nearest_topic_name, :maximum => 255, :allow_blank => true, :allow_nil => true
- sa.validates :nearest_topic_name, length: { maximum: 255 }, allow_blank: true
- end
-
- with_options if: :physical_hub_restricted? do |sa|
- # HUB-25
- #sa.validates_length_of :nearest_topic_name, :maximum => 60, :allow_blank => true, :allow_nil => true
- sa.validates :nearest_topic_name, length: { maximum: 60 }, allow_blank: true
- # HUB-28
- #sa.validates_presence_of :coordinates
- sa.validates :coordinates, presence: true
- # HUB-29
- #sa.validates_length_of :city_name, :minimum => 1, :maximum => 80
- sa.validates :city_name, length: { in: 1..80 }
- # HUB-30
- #sa.validates_format_of :country_code, :with => %r{\A[\d]{5}\z}
- sa.validates :country_code, presence: true, numericality: { only_integer: true }, length: { is: 5 }
- # HUB-31
- #sa.validates_length_of :comment, :maximum => 255, :allow_blank => true, :allow_nil => true
- sa.validates :comment, length: { maximum: 255 }, allow_blank: true
- #sa.validates :registration_number, :numericality => { :less_than => 10 ** 8 }
- sa.validates :registration_number, presence: true, numericality: { less_than: 10 ** 8 }
- end
- end
- def specific_objectid
- validate_specific_objectid(12)
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/hub/time_table_restrictions.rb b/lib/ninoxe_extension/hub/time_table_restrictions.rb
deleted file mode 100644
index b61d1e05a..000000000
--- a/lib/ninoxe_extension/hub/time_table_restrictions.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# -*- coding: utf-8 -*-
-module NinoxeExtension::Hub
- module TimeTableRestrictions
- extend ActiveSupport::Concern
-
- included do
- include ObjectidRestrictions
-
- with_options if: :hub_restricted? do |tt|
- # HUB-44
- tt.validate :specific_objectid
- # HUB-45
- #tt.validates_length_of :comment, :maximum => 75, :allow_blank => true, :allow_nil => true
- tt.validates :comment, length: { maximum: 75 }, allow_blank: true
- end
- end
- def specific_objectid
- validate_specific_objectid( 6)
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb b/lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb
deleted file mode 100644
index b1a493207..000000000
--- a/lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# -*- coding: utf-8 -*-
-module NinoxeExtension::Hub
- module VehicleJourneyRestrictions
- extend ActiveSupport::Concern
-
- included do
- include ObjectidRestrictions
-
- # HUB-42
- with_options if: :hub_restricted? do |vj|
- vj.validate :specific_objectid
- end
- end
- def specific_objectid
- validate_specific_objectid( 8)
- end
- end
-end
-
diff --git a/lib/ninoxe_extension/projection_fields.rb b/lib/ninoxe_extension/projection_fields.rb
deleted file mode 100644
index 25d30df94..000000000
--- a/lib/ninoxe_extension/projection_fields.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-
- module NinoxeExtension::ProjectionFields
- extend ActiveSupport::Concern
-
- included do
- #attr_accessible :projection_x,:projection_y,:projection_xy
-
- # add projection_type set on pre-insert and pre_update action
- before_save :set_projections
- def set_projections
- if ! self.coordinates.blank?
- self.long_lat_type = 'WGS84'
- else
- self.long_lat_type = nil
- end
- end
-
- def projection
- if self.referential.projection_type.nil? || self.referential.projection_type.empty?
- nil
- else
- self.referential.projection_type
- end
- end
- @point = nil
-
- def projection_x
- if self.long_lat_type.nil? || self.projection.nil?
- nil
- else
- @point ||= GeoRuby::SimpleFeatures::Point::from_lat_lng(Geokit::LatLng.new(self.latitude,self.longitude)).project_to(self.projection.to_i)
- @point.x
- end
- end
- def projection_y
- if self.long_lat_type.nil? || self.projection.nil?
- nil
- else
- @point ||= GeoRuby::SimpleFeatures::Point::from_lat_lng(Geokit::LatLng.new(self.latitude,self.longitude)).project_to(self.projection.to_i)
- @point.y
- end
- end
- def projection_xy
- if self.long_lat_type.nil? || self.projection.nil?
- nil
- else
- @point ||= GeoRuby::SimpleFeatures::Point::from_lat_lng(Geokit::LatLng.new(self.latitude,self.longitude)).project_to(self.projection.to_i)
- @point.x.to_s+","+@point.y.to_s
- end
- end
- def projection_x=(dummy)
- # dummy method
- end
- def projection_y=(dummy)
- # dummy method
- end
- def projection_xy=(dummy)
- # dummy method
- end
- end
- end
-
-