Sha256: 17b4d7210a6a73e81475036f1584d11be297b647c61249ed61193a01f092ef71

Contents?: true

Size: 638 Bytes

Versions: 6

Compression:

Stored size: 638 Bytes

Contents

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ransack-0.4.2 lib/ransack/ransacker.rb
ransack-0.4.1 lib/ransack/ransacker.rb
ransack-0.4.0 lib/ransack/ransacker.rb
ransack-0.3.0 lib/ransack/ransacker.rb
ransack-0.2.1 lib/ransack/ransacker.rb
ransack-0.2.0 lib/ransack/ransacker.rb