Sha256: ed398cc926f9a6da27ac34124e57334c4059f46f37606c403e5d5f126df5405d

Contents?: true

Size: 774 Bytes

Versions: 1

Compression:

Stored size: 774 Bytes

Contents

module Encore
  class Attribute
    attr_reader :attribute, :klass

    def initialize(klass, attribute, opts = {})
      @klass = klass
      @attribute = attribute
      @opts = opts
    end

    def self.map_attributes(klass, params)
      params.inject({}) do |memo, (attribute, value)|
        memo.merge Attribute.new(klass, attribute.to_sym) => value
      end
    end

    def ==(other_attribute)
      hash == other_attribute.hash
    end

    def eql?(other)
      self == other
    end

    # Generate a hash for comparisons
    def hash
      [@attribute, @klass].hash
    end

    # Return whether the attribute is read-only
    def readonly?
      !!@opts[:readonly]
    end

    def to_s
      "#<Encore::Attribute #{@klass}@#{@attribute}>"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
encore-0.0.2 lib/encore/attribute.rb