Sha256: d12c5f26067dab1ba876fcb8b49c667df934058da6a0967702b7f0db45204af2

Contents?: true

Size: 1.15 KB

Versions: 13

Compression:

Stored size: 1.15 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
          return 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

13 entries across 13 versions & 1 rubygems

Version Path
ransack-2.4.1 lib/ransack/nodes/attribute.rb
ransack-2.4.0 lib/ransack/nodes/attribute.rb
ransack-2.3.2 lib/ransack/nodes/attribute.rb
ransack-2.3.1 lib/ransack/nodes/attribute.rb
ransack-2.3.0 lib/ransack/nodes/attribute.rb
ransack-1.8.10 lib/ransack/nodes/attribute.rb
ransack-2.1.1 lib/ransack/nodes/attribute.rb
ransack-2.1.0 lib/ransack/nodes/attribute.rb
ransack-2.0.1 lib/ransack/nodes/attribute.rb
ransack-2.0.0 lib/ransack/nodes/attribute.rb
ransack-1.8.9 lib/ransack/nodes/attribute.rb
ransack-1.8.8 lib/ransack/nodes/attribute.rb
ransack-1.8.7 lib/ransack/nodes/attribute.rb