Class: TransportationRoute

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/transportation_route.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.associated_modelsObject

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_arrayObject

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_recordsObject

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

#testObject



67
68
69
# File 'app/models/transportation_route.rb', line 67

def test
  puts self.name
end