Class: TransportationRoute
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- TransportationRoute
- Defined in:
- app/models/transportation_route.rb
Overview
create_table :transportation_routes do |t|
t.string :internal_identifier
t.string :description
t.string :comments
t.string :external_identifier
t.string :external_id_source
t.
end
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.
Class Method Summary collapse
- .open_entries ⇒ Object
-
.scope_by_dba_organization(dba_organization) ⇒ ActiveRecord::Relation
(also: scope_by_dba)
scope by dba organization.
-
.scope_by_party(party, options = {}) ⇒ ActiveRecord::Relation
scope by party.
-
.scope_by_user(user, options = {}) ⇒ ActiveRecord::Relation
scope by work efforts assigned to the passed user.
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.
- #to_data_hash ⇒ Object
Class Attribute Details
.associated_models ⇒ Object
Returns the value of attribute associated_models.
25 26 27 |
# File 'app/models/transportation_route.rb', line 25 def associated_models @associated_models end |
Instance Attribute Details
#associated_records_array ⇒ Object
declare array to related models
21 22 23 |
# File 'app/models/transportation_route.rb', line 21 def associated_records_array @associated_records_array end |
Class Method Details
.open_entries ⇒ Object
55 56 57 58 59 |
# File 'app/models/transportation_route.rb', line 55 def open_entries joins(:segments) .where(transportation_routes: {manual_entry: false}) .where(transportation_route_segments: {actual_arrival: nil}) end |
.scope_by_dba_organization(dba_organization) ⇒ ActiveRecord::Relation Also known as: scope_by_dba
scope by dba organization
74 75 76 |
# File 'app/models/transportation_route.rb', line 74 def scope_by_dba_organization(dba_organization) scope_by_party(dba_organization, {role_types: ['dba_org']}) end |
.scope_by_party(party, options = {}) ⇒ ActiveRecord::Relation
scope by party
or an array of Party ids
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/models/transportation_route.rb', line 99 def scope_by_party(party, ={}) table_alias = String.random if [:role_types] joins("inner join entity_party_roles as #{table_alias} on #{table_alias}.entity_record_type = 'TransportationRoute' and #{table_alias}.entity_record_id = transportation_routes.id and #{table_alias}.role_type_id in (#{RoleType.find_child_role_types([:role_types]).collect(&:id).join(',')}) and #{table_alias}.party_id in (#{Party.select('id').where(id: party).to_sql})") else joins("inner join entity_party_roles as #{table_alias} on #{table_alias}.entity_record_type = 'TransportationRoute' and #{table_alias}.entity_record_id = transportation_routes.id and #{table_alias}.party_id in (#{Party.select('id').where(id: party).to_sql})") end end |
.scope_by_user(user, options = {}) ⇒ ActiveRecord::Relation
scope by work efforts assigned to the passed user
87 88 89 |
# File 'app/models/transportation_route.rb', line 87 def scope_by_user(user, ={}) scope_by_party(user.party, ) end |
Instance Method Details
#associated_records ⇒ Object
Gets all associated records (of any class) tied to this route
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/models/transportation_route.rb', line 117 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
132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'app/models/transportation_route.rb', line 132 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 |
#to_data_hash ⇒ Object
147 148 149 150 151 152 153 154 |
# File 'app/models/transportation_route.rb', line 147 def to_data_hash data = to_hash(only: [:id, :internal_identifier, :description, :comments, :created_at, :updated_at]) data[:transportation_route_segments] = segments.collect { |item| item.to_data_hash } data end |