Sha256: 7d4b7e3433a7b10d8fa979b7dc63ec3a46828f2e0979e3cc6cf1f7d9598bfe7f

Contents?: true

Size: 1.14 KB

Versions: 10

Compression:

Stored size: 1.14 KB

Contents

module Ransack
  module Nodes
    class Attribute < Node
      include Bindable

      attr_reader :name, :ransacker_args

      delegate :blank?, :present?, :to => :name
      delegate :engine, :to => :context

      def initialize(context, name = nil, ransacker_args = [])
        super(context)
        self.name = name unless name.blank?
        @ransacker_args = ransacker_args
      end

      def name=(name)
        @name = name
      end

      def valid?
        bound? && attr &&
        context.klassify(parent).ransackable_attributes(context.auth_object)
        .include?(attr_name.split('.').last)
      end

      def associated_collection?
        parent.respond_to?(:reflection) && parent.reflection.collection?
      end

      def type
        if ransacker
          ransacker.type
        else
          context.type_for(self)
        end
      end

      def eql?(other)
        self.class == other.class &&
        self.name == other.name
      end
      alias :== :eql?

      def hash
        self.name.hash
      end

      def persisted?
        false
      end

      def inspect
        "Attribute <#{name}>"
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
ransack-3.2.1 lib/ransack/nodes/attribute.rb
ransack-3.2.0 lib/ransack/nodes/attribute.rb
ransack-3.1.0 lib/ransack/nodes/attribute.rb
ransack-3.0.1 lib/ransack/nodes/attribute.rb
ransack-3.0.0 lib/ransack/nodes/attribute.rb
ransack-2.6.0 lib/ransack/nodes/attribute.rb
ransack-2.5.0 lib/ransack/nodes/attribute.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/ransack-2.4.2/lib/ransack/nodes/attribute.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/ransack-2.4.2/lib/ransack/nodes/attribute.rb
ransack-2.4.2 lib/ransack/nodes/attribute.rb