foreman/app/models/host.rb @ 783fb4aa
d7611b24 | Greg Sutcliffe | module Host
|
|
def self.method_missing(method, *args, &block)
|
|||
796352ed | Greg Sutcliffe | type = "Host::Managed"
|
|
case method.to_s
|
|||
when /create/, 'new'
|
|||
feacea35 | Amos Benari | if args.empty? or args[0].nil? # got no parameters
|
|
796352ed | Greg Sutcliffe | #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.
|
|||
9fd7478e | Paul Kelly | end
|
|
end
|
|||
796352ed | Greg Sutcliffe | ||
type.constantize.send(method,*args, &block)
|
|||
9fd7478e | Paul Kelly | end
|
|
d7611b24 | Greg Sutcliffe | # 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
|
|||
def self.respond_to?(method, include_private = false)
|
|||
a6b0eeb0 | Joseph Magen | if method.to_s =~ /\Afind_by_(.*)\Z/
|
|
d7611b24 | Greg Sutcliffe | true
|
|
15daa32c | Ohad Levy | else
|
|
d7611b24 | Greg Sutcliffe | super
|
|
15daa32c | Ohad Levy | end
|
|
end
|
|||
796352ed | Greg Sutcliffe | end
|