aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/chouette/for_alighting_enumerations.rb2
-rw-r--r--app/models/chouette/route.rb64
-rw-r--r--app/models/concerns/route_restrictions.rb2
-rw-r--r--app/models/line_referential.rb2
4 files changed, 15 insertions, 55 deletions
diff --git a/app/models/chouette/for_alighting_enumerations.rb b/app/models/chouette/for_alighting_enumerations.rb
index 4f34927d3..ab07a670d 100644
--- a/app/models/chouette/for_alighting_enumerations.rb
+++ b/app/models/chouette/for_alighting_enumerations.rb
@@ -2,7 +2,7 @@ module Chouette
module ForAlightingEnumerations
extend Enumerize
extend ActiveModel::Naming
-
+
enumerize :for_alighting, in: %w[normal forbidden request_stop is_flexible]
end
end
diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb
index 8949a6bc2..446eb5f70 100644
--- a/app/models/chouette/route.rb
+++ b/app/models/chouette/route.rb
@@ -1,14 +1,17 @@
class Chouette::Route < Chouette::TridentActiveRecord
include RouteRestrictions
+ extend Enumerize
+ extend ActiveModel::Naming
+
+ enumerize :direction, in: %i(straight_forward backward clockwise counter_clockwise north north_west west south_west south south_east east north_east)
+ enumerize :wayback, in: %i(straight_forward backward)
+
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
self.primary_key = "id"
- attr_accessor :wayback_code
- attr_accessor :direction_code
-
def self.nullable_attributes
- [:published_name, :comment, :number, :name]
+ [:published_name, :comment, :number, :name, :direction, :wayback]
end
belongs_to :line
@@ -61,8 +64,11 @@ class Chouette::Route < Chouette::TridentActiveRecord
# validates_presence_of :name
validates_presence_of :line
- # validates_presence_of :direction_code
- # validates_presence_of :wayback_code
+ # validates_presence_of :direction
+ # validates_presence_of :wayback
+
+ validates :direction, inclusion: { in: self.direction.values }
+ validates :wayback, inclusion: { in: self.wayback.values }
before_destroy :dereference_opposite_route
@@ -96,52 +102,6 @@ class Chouette::Route < Chouette::TridentActiveRecord
.order( "vehicle_journey_at_stops.departure_time")
end
- def self.direction_binding
- { "A" => "straight_forward",
- "R" => "backward",
- "ClockWise" => "clock_wise",
- "CounterClockWise" => "counter_clock_wise",
- "North" => "north",
- "NorthWest" => "north_west",
- "West" => "west",
- "SouthWest" => "south_west",
- "South" => "south",
- "SouthEast" => "south_east",
- "East" => "east",
- "NorthEast" => "north_east"}
- end
- def direction_code
- return nil if self.class.direction_binding[direction].nil?
- Chouette::Direction.new( self.class.direction_binding[direction])
- end
- def direction_code=(direction_code)
- self.direction = nil
- self.class.direction_binding.each do |k,v|
- self.direction = k if v==direction_code
- end
- end
- @@directions = nil
- def self.directions
- @@directions ||= Chouette::Direction.all
- end
- def self.wayback_binding
- { "A" => "straight_forward", "R" => "backward"}
- end
- def wayback_code
- return nil if self.class.wayback_binding[wayback].nil?
- Chouette::Wayback.new( self.class.wayback_binding[wayback])
- end
- def wayback_code=(wayback_code)
- self.wayback = nil
- self.class.wayback_binding.each do |k,v|
- self.wayback = k if v==wayback_code
- end
- end
- @@waybacks = nil
- def self.waybacks
- @@waybacks ||= Chouette::Wayback.all
- end
-
def stop_point_permutation?( stop_point_ids)
stop_points.map(&:id).map(&:to_s).sort == stop_point_ids.map(&:to_s).sort
end
diff --git a/app/models/concerns/route_restrictions.rb b/app/models/concerns/route_restrictions.rb
index 5a098d86f..4a21cbccf 100644
--- a/app/models/concerns/route_restrictions.rb
+++ b/app/models/concerns/route_restrictions.rb
@@ -8,7 +8,7 @@ module RouteRestrictions
# 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)
+ errors.add( :wayback, I18n.t('hub.routes.wayback_code_exclusive')) if line.routes.reject {|r| r.id==id}.map(&:wayback).include?( wayback)
end
# HUB-37
diff --git a/app/models/line_referential.rb b/app/models/line_referential.rb
index 7d3b638cb..e1f048fd8 100644
--- a/app/models/line_referential.rb
+++ b/app/models/line_referential.rb
@@ -6,7 +6,7 @@ class LineReferential < ActiveRecord::Base
has_many :group_of_lines, class_name: 'Chouette::GroupOfLine'
has_many :companies, class_name: 'Chouette::Company'
has_many :networks, class_name: 'Chouette::Network'
- has_many :line_referential_syncs, -> { order created_at: :desc}
+ has_many :line_referential_syncs, -> { order created_at: :desc }
has_many :workbenches
def add_member(organisation, options = {})