Class: Cats::Core::Route

Inherits:
ApplicationRecord show all
Defined in:
app/models/cats/core/route.rb

Class Method Summary collapse

Instance Method Summary collapse

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_nameObject



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_destinationObject



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_regionObject



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_routeObject



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

#validate_sourceObject



27
28
29
30
31
# File 'app/models/cats/core/route.rb', line 27

def validate_source
  return unless source

  errors.add(:source, "cannot be a region.") if source.location_type == Location::REGION
end