Module: Peck::Rails::Controller::Fixtures

Defined in:
lib/peck_on_rails/controller.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Filter calls to fixture methods so we can use them in the context definition



49
50
51
52
53
54
55
56
# File 'lib/peck_on_rails/controller.rb', line 49

def method_missing(method, *arguments, &block)
  if known_fixture?(method)
    arguments = arguments.map { |a| a.inspect }
    ::Peck::Rails::Controller::LazyValue.new("#{method}(#{arguments.join(', ')})")
  else
    super
  end
end

Instance Method Details

#known_fixture?(name) ⇒ Boolean

Returns true when the passed name is a known table, we assume known tables also have fixtures

Returns:

  • (Boolean)


44
45
46
# File 'lib/peck_on_rails/controller.rb', line 44

def known_fixture?(name)
  respond_to?(:fixture_table_names) && fixture_table_names.include?(name.to_s)
end