aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorLuc Donnet2018-01-31 12:20:25 +0100
committerGitHub2018-01-31 12:20:25 +0100
commit4fa30ef61bd334de0627267b7b2eda4e09c8b728 (patch)
treefa73d3d20cfa67a818b6f1d5f3a0a03898659cad /app/models
parente54ee3a4379afb763906ab2ba2fd980349c48334 (diff)
parentc463c3a950246c4c2660ce7df1c1ea8f2acbe578 (diff)
downloadchouette-core-4fa30ef61bd334de0627267b7b2eda4e09c8b728.tar.bz2
Merge pull request #263 from af83/5750-non-commercial-stop-areas
5750 non commercial stop areas
Diffstat (limited to 'app/models')
-rw-r--r--app/models/chouette/area_type.rb25
-rw-r--r--app/models/chouette/stop_area.rb18
2 files changed, 36 insertions, 7 deletions
diff --git a/app/models/chouette/area_type.rb b/app/models/chouette/area_type.rb
index 4703ea646..e17d2ee8d 100644
--- a/app/models/chouette/area_type.rb
+++ b/app/models/chouette/area_type.rb
@@ -1,13 +1,22 @@
class Chouette::AreaType
include Comparable
- ALL = %i(zdep zder zdlp zdlr lda gdl).freeze
+ COMMERCIAL = %i(zdep zder zdlp zdlr lda gdl).freeze
+ NON_COMMERCIAL = %i(deposit border service_area relief other).freeze
+ ALL = COMMERCIAL + NON_COMMERCIAL
+ @@commercial = COMMERCIAL
+ @@non_commercial = NON_COMMERCIAL
@@all = ALL
- mattr_accessor :all
+ mattr_accessor :all, :commercial, :non_commercial
- def self.all=(values)
- @@all = ALL & values
+ def self.commercial=(values)
+ @@commercial = COMMERCIAL & values
+ reset_caches!
+ end
+
+ def self.non_commercial=(values)
+ @@non_commercial = NON_COMMERCIAL & values
reset_caches!
end
@@ -20,12 +29,14 @@ class Chouette::AreaType
end
def self.reset_caches!
+ @@all = @@commercial + @@non_commercial
@@instances = {}
- @@options = nil
+ @@options = {}
end
- def self.options
- @@options ||= all.map { |c| find(c) }.map { |t| [ t.label, t.code ] }
+ def self.options(kind=:all)
+ @@options ||= {}
+ @@options[kind] ||= self.send(kind).map { |c| find(c) }.map { |t| [ t.label, t.code ] }
end
attr_reader :code
diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb
index ea1855ea8..ad42d54ae 100644
--- a/app/models/chouette/stop_area.rb
+++ b/app/models/chouette/stop_area.rb
@@ -10,6 +10,7 @@ module Chouette
extend Enumerize
enumerize :area_type, in: Chouette::AreaType::ALL
+ enumerize :kind, in: %i(commercial non_commercial)
with_options dependent: :destroy do |assoc|
assoc.has_many :stop_points
@@ -31,6 +32,7 @@ module Chouette
validates_format_of :registration_number, :with => %r{\A[\d\w_\-]+\Z}, :allow_blank => true
validates_presence_of :name
+ validates_presence_of :kind
validates_presence_of :latitude, :if => :longitude
validates_presence_of :longitude, :if => :latitude
validates_numericality_of :latitude, :less_than_or_equal_to => 90, :greater_than_or_equal_to => -90, :allow_nil => true
@@ -41,6 +43,7 @@ module Chouette
validates_numericality_of :waiting_time, greater_than_or_equal_to: 0, only_integer: true, if: :waiting_time
validate :parent_area_type_must_be_greater
+ validate :area_type_of_right_kind
def self.nullable_attributes
[:registration_number, :street_name, :country_code, :fare_code,
@@ -56,6 +59,13 @@ module Chouette
end
end
+ def area_type_of_right_kind
+
+ unless Chouette::AreaType.send(self.kind).map(&:to_s).include?(self.area_type)
+ errors.add(:area_type, I18n.t('stop_areas.errors.incorrect_kind_area_type'))
+ end
+ end
+
after_update :clean_invalid_access_links
before_save :coordinates_to_lat_lng
@@ -96,6 +106,10 @@ module Chouette
end
end
+ def local_id
+ id.to_s
+ end
+
def children_in_depth
return [] if self.children.empty?
@@ -374,5 +388,9 @@ module Chouette
return nil unless time_zone.present?
ActiveSupport::TimeZone[time_zone]&.formatted_offset
end
+
+ def commercial?
+ kind == "commercial"
+ end
end
end