Class: TransportationRoute
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- TransportationRoute
- Defined in:
- app/models/transportation_route.rb
Class Attribute Summary collapse
-
.associated_models ⇒ Object
Returns the value of attribute associated_models.
Instance Attribute Summary collapse
-
#associated_records_array ⇒ Object
declare array to related models.
Instance Method Summary collapse
-
#associated_records ⇒ Object
Gets all associated records (of any class) tied to this route.
-
#modify_stops(segment) ⇒ Object
Ties a segment’s from/to stops to its route, and then forces a reload of the route’s stops array from its cached value.
- #test ⇒ Object
Class Attribute Details
.associated_models ⇒ Object
Returns the value of attribute associated_models.
8 9 10 |
# File 'app/models/transportation_route.rb', line 8 def associated_models @associated_models end |
Instance Attribute Details
#associated_records_array ⇒ Object
declare array to related models
5 6 7 |
# File 'app/models/transportation_route.rb', line 5 def associated_records_array @associated_records_array end |
Instance Method Details
#associated_records ⇒ Object
Gets all associated records (of any class) tied to this route
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/transportation_route.rb', line 37 def associated_records #used the declared instance variable array records = self.send("associated_records_array") records = records || [] self.class.associated_models.each do |model| records = records | self.send(model.to_s) end #set it back to the instance variable self.send("associated_records_array=", records) records end |
#modify_stops(segment) ⇒ Object
Ties a segment’s from/to stops to its route, and then forces a reload of the route’s stops array from its cached value
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/transportation_route.rb', line 52 def modify_stops(segment) stops = [] stops << segment.from_stop << segment.to_stop stops.each do |stop| unless stop.nil? or stop.route == self stop.route = self stop.save end end # Force reload of the stops array since it has changed self.stops(true) end |
#test ⇒ Object
67 68 69 |
# File 'app/models/transportation_route.rb', line 67 def test puts self.name end |