Module: Host

Defined in:
app/models/host.rb,
app/models/host/base.rb,
app/models/host/hostmix.rb

Defined Under Namespace

Modules: Hostmix Classes: Base, Managed

Class Method Summary collapse

Class Method Details

.method_missing(method, *args, &block) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/models/host.rb', line 3

def self.method_missing(method, *args, &block)
  type = "Host::Managed"
  case method.to_s
  when /create/, 'new'
    if args.empty? or args[0].nil? # got no parameters
      #set the default type
      args = [{:type => type}]
    else # got some parameters
      args[0][:type] ||= type # adds the type if it doesnt exists
      type = args[0][:type]   # stores the type for later usage.
    end
  end

  type.constantize.send(method,*args, &block)
end

.respond_to?(method, include_private = false) ⇒ Boolean

the API base controller expects to call 'respond_to?' on this, which this module doesn't have. So we stub it out to make that logic work for the “find_by_*” classes that Rails will provide


22
23
24
25
26
27
28
# File 'app/models/host.rb', line 22

def self.respond_to?(method, include_private = false)
  if method.to_s =~ /^find_by_(.*)$/
    true
  else
    super
  end
end