Sha256: b072eb7ec43087661b8abb194648c1d548b3cf2d29f6982574ee8de21db7bde4

Contents?: true

Size: 922 Bytes

Versions: 7

Compression:

Stored size: 922 Bytes

Contents

module Ransack
  module Nodes
    class Attribute < Node
      include Bindable

      attr_reader :name

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

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

      def name=(name)
        @name = name
        context.bind(self, name) unless name.blank?
      end

      def valid?
        bound? && attr
      end

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

      def cast_value(value)
        value.cast_to_type(type)
      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

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ransack-0.5.1 lib/ransack/nodes/attribute.rb
ransack-0.5.0 lib/ransack/nodes/attribute.rb
ransack-0.4.2 lib/ransack/nodes/attribute.rb
ransack-0.4.1 lib/ransack/nodes/attribute.rb
ransack-0.4.0 lib/ransack/nodes/attribute.rb
ransack-0.3.0 lib/ransack/nodes/attribute.rb
ransack-0.2.1 lib/ransack/nodes/attribute.rb