Class: Ransack::Ransacker

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, name, opts = {}, &block) ⇒ Ransacker

Returns a new instance of Ransacker.



8
9
10
11
12
13
14
15
16
17
# File 'lib/ransack/ransacker.rb', line 8

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]}
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



4
5
6
# File 'lib/ransack/ransacker.rb', line 4

def args
  @args
end

#formatterObject (readonly)

Returns the value of attribute formatter.



4
5
6
# File 'lib/ransack/ransacker.rb', line 4

def formatter
  @formatter
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/ransack/ransacker.rb', line 4

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/ransack/ransacker.rb', line 4

def type
  @type
end

Instance Method Details

#attr_from(bindable) ⇒ Object



19
20
21
# File 'lib/ransack/ransacker.rb', line 19

def attr_from(bindable)
  call(*args.map {|arg| bindable.send(arg)})
end