2011-04-12 00:07:23 +00:00
|
|
|
module Ransack
|
|
|
|
class Ransacker
|
|
|
|
|
|
|
|
attr_reader :name, :type, :formatter, :args
|
|
|
|
|
2014-05-01 13:55:39 +00:00
|
|
|
delegate :call, :to => :@callable
|
2011-04-12 00:07:23 +00:00
|
|
|
|
|
|
|
def initialize(klass, name, opts = {}, &block)
|
|
|
|
@klass, @name = klass, name
|
|
|
|
|
|
|
|
@type = opts[:type] || :string
|
|
|
|
@args = opts[:args] || [:parent]
|
|
|
|
@formatter = opts[:formatter]
|
|
|
|
@callable = opts[:callable] || block ||
|
|
|
|
(@klass.method(name) if @klass.respond_to?(name)) ||
|
2014-01-02 09:48:41 +00:00
|
|
|
proc { |parent| parent.table[name] }
|
2011-04-12 00:07:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def attr_from(bindable)
|
2014-01-02 09:48:41 +00:00
|
|
|
call(*args.map { |arg| bindable.send(arg) })
|
2011-04-12 00:07:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2013-12-10 14:00:44 +00:00
|
|
|
end
|