aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorZakaria BOUZIANE2015-03-09 14:40:32 +0100
committerZakaria BOUZIANE2015-03-09 14:40:32 +0100
commit05fb2b7aa8ca7d490a8960a096de7d934fffe133 (patch)
tree9b6666380cdbd2eff1f79c79d97fbd302a768006 /lib
parent0d5adf2fad5c0ddd8efc1eca9dc6d8e9c48b049d (diff)
parenta5f66f953120c08951b6338ad0f743c2d0eec86e (diff)
downloadchouette-core-05fb2b7aa8ca7d490a8960a096de7d934fffe133.tar.bz2
Solving merge V2_5 pbs
Diffstat (limited to 'lib')
-rw-r--r--lib/ninoxe_extension/hub/company_restrictions.rb20
-rw-r--r--lib/ninoxe_extension/hub/connection_link_restrictions.rb16
-rw-r--r--lib/ninoxe_extension/hub/group_of_line_restrictions.rb21
-rw-r--r--lib/ninoxe_extension/hub/journey_pattern_restrictions.rb20
-rw-r--r--lib/ninoxe_extension/hub/line_restrictions.rb25
-rw-r--r--lib/ninoxe_extension/hub/network_restrictions.rb20
-rw-r--r--lib/ninoxe_extension/hub/objectid_restrictions.rb22
-rw-r--r--lib/ninoxe_extension/hub/route_restrictions.rb29
-rw-r--r--lib/ninoxe_extension/hub/stop_area_restrictions.rb53
-rw-r--r--lib/ninoxe_extension/hub/time_table_restrictions.rb18
-rw-r--r--lib/ninoxe_extension/hub/vehicle_journey_restrictions.rb16
-rw-r--r--lib/tasks/stats.rake3
12 files changed, 263 insertions, 0 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
new file mode 100644
index 000000000..a5f4c8019
--- /dev/null
+++ b/lib/ninoxe_extension/hub/route_restrictions.rb
@@ -0,0 +1,29 @@
+# -*- 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'))
+ end
+
+ # HUB-38
+ with_options if: :hub_restricted? do |route|
+ route.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,8}$}
+ 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
+
diff --git a/lib/tasks/stats.rake b/lib/tasks/stats.rake
index 4907bb4eb..4f2739664 100644
--- a/lib/tasks/stats.rake
+++ b/lib/tasks/stats.rake
@@ -19,6 +19,9 @@ namespace :stats do
1.upto(12) do |i|
stats << class_for_stat.all.select {|o| o.created_at.month==i && o.created_at.year==2014}.count
end
+ 1.upto(12) do |i|
+ stats << class_for_stat.all.select {|o| o.created_at.month==i && o.created_at.year==2015}.count
+ end
s.puts stats.join(",")
end
end