require 'hashie'

module Attrocity
  class AttributesHash < Hash
    include Hashie::Extensions::MergeInitializer
    include Hashie::Extensions::IndifferentAccess
  end

  class AttributeSet
    attr_reader :attributes

    def initialize(attributes=[])
      @attributes = attributes
    end

    def deep_clone
      self.class.new(attributes.collect(&:deep_clone))
    end

    def <<(attribute)
      attributes << attribute
    end

    def to_h
      # TODO: return a hash of attribute names and values
    end

    def set_values(data)
      attributes_hash = AttributesHash.new(data)
      attributes.each do |attr|
        attr.value = attributes_hash.fetch(attr.name)
      end
    end
  end
end

require 'hashie'

module Attrocity
  class AttributesHash < Hash
    include Hashie::Extensions::MergeInitializer
    include Hashie::Extensions::IndifferentAccess
  end

  class AttributeSet
    attr_reader :attributes

    def initialize(attributes=[])
      @attributes = attributes
    end

    def deep_clone
      self.class.new(attributes.collect(&:deep_clone))
    end

    def add(attribute)
      attributes << attribute
    end
    alias_method :<<, :add

    def to_h
      # TODO: return a hash of attribute names and values
    end

    def set_values(data)
      attributes_hash = AttributesHash.new(data)
      attributes.each do |attr|
        attr.value = attributes_hash.fetch(attr.name)
      end
    end
  end
end

Use add as method name and alias shovel
[TS][000000] Use add as method name and alias shovel

Although we're not necessarily emulating a Ruby Set class in
AttributeSet, using #add like a Set does is clearer.
