Class: M2Config::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/m2config/route.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fields) ⇒ Route

Returns a new instance of Route.



5
6
7
8
9
10
11
# File 'lib/m2config/route.rb', line 5

def initialize( fields )
  fields[:target_id] = fields[:target].id
  fields[:target_type] = fields[:target].type
  fields.delete(:target)
  super(fields, false)
  save
end

Class Method Details

.elect!(route66) ⇒ Object



13
14
15
16
17
# File 'lib/m2config/route.rb', line 13

def self.elect!( route66 )
  toMatch = {path: route66.path, host_id: route66.host_id}
  toExclude = {id: route66.id}
  Route.where(toMatch).exclude(toExclude).delete
end

Instance Method Details

#host=(hostOrId) ⇒ Object



19
20
21
22
# File 'lib/m2config/route.rb', line 19

def host=( hostOrId )
  self.host_id = hostOrId.kind_of?(Host) ? hostOrId.id : hostOrId
  save
end

#targetObject



30
31
32
33
34
35
36
# File 'lib/m2config/route.rb', line 30

def target
  case target_type
  when "proxy" then Proxy[target_id]
  when "dir" then Dir[target_id]
  when "handler" then Handler[target_id]
  end
end

#target=(newTarget) ⇒ Object



24
25
26
27
28
# File 'lib/m2config/route.rb', line 24

def target=( newTarget )
  self.target_id = newTarget.id
  self.target_type = newTarget.type
  save
end