mirror of
https://github.com/activerecord-hackery/ransack.git
synced 2022-11-09 13:47:45 -05:00
26 lines
No EOL
638 B
Ruby
26 lines
No EOL
638 B
Ruby
module Ransack
|
|
class Ransacker
|
|
|
|
attr_reader :name, :type, :formatter, :args
|
|
|
|
delegate :call, :to => :@callable
|
|
|
|
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)) ||
|
|
proc {|parent| parent.table[name]}
|
|
|
|
@klass._ransackers[name.to_s] = self
|
|
end
|
|
|
|
def attr_from(bindable)
|
|
call(*args.map {|arg| bindable.send(arg)})
|
|
end
|
|
|
|
end
|
|
end |