Class: Cats::Core::Route
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Cats::Core::Route
- Defined in:
- app/models/cats/core/route.rb
Class Method Summary collapse
- .ransackable_associations(_auth_object = nil) ⇒ Object
- .ransackable_attributes(_auth_object = nil) ⇒ Object
Instance Method Summary collapse
- #set_name ⇒ Object
- #validate_destination ⇒ Object
- #validate_region ⇒ Object
- #validate_route ⇒ Object
- #validate_source ⇒ Object
Class Method Details
.ransackable_associations(_auth_object = nil) ⇒ Object
56 57 58 59 60 61 62 |
# File 'app/models/cats/core/route.rb', line 56 def self.ransackable_associations(_auth_object = nil) %w[ region source destination ] end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'app/models/cats/core/route.rb', line 47 def self.ransackable_attributes(_auth_object = nil) %w[ destination_id name region_id source_id ] end |
Instance Method Details
#set_name ⇒ Object
15 16 17 18 19 |
# File 'app/models/cats/core/route.rb', line 15 def set_name return unless source && destination self.name = "#{source.name} - #{destination.name}" end |
#validate_destination ⇒ Object
33 34 35 36 37 |
# File 'app/models/cats/core/route.rb', line 33 def validate_destination return unless destination errors.add(:destination, "cannot be a region.") if destination.location_type == Location::REGION end |
#validate_region ⇒ Object
21 22 23 24 25 |
# File 'app/models/cats/core/route.rb', line 21 def validate_region return unless region errors.add(:region, "should be a valid region.") unless region.location_type == Location::REGION end |
#validate_route ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/models/cats/core/route.rb', line 39 def validate_route return unless source return unless destination errors.add(:base, "Source and destination cannot be the same") if source == destination end |