Class: Fofof

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

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Fofof

Returns a new instance of Fofof.



8
9
10
# File 'lib/fofof.rb', line 8

def initialize(model)
  @model = model
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *arguments, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fofof.rb', line 12

def method_missing(method, *arguments, &block)
  ret = @model.send(method, *arguments, &block)
  if ret.nil?
    raise ActiveRecord::RecordNotFound.new
  end
  return ret
rescue ActiveRecord::RecordNotFound => e
  if arguments.last.is_a? Hash
    arguments = arguments[0..-2].inspect[1..-2] + ", " + arguments.last.inspect[1..-2]
  else
    arguments = arguments.inspect[1..-2]
  end
  raise NotFound.new("Not found: #{@model.name}.#{method}(#{arguments}): #{e.message}")
end