Sha256: 0f0cf6ba2ffc59372c60859e2628126b10075f37ee9e5bcab472b6ac0bea0767

Contents?: true

Size: 728 Bytes

Versions: 12

Compression:

Stored size: 728 Bytes

Contents

module Sprig
  module Seed
    class AttributeCollection
      include Enumerable

      delegate :each, :to => :attributes

      def initialize(attrs_hash)
        @attrs_hash = attrs_hash.to_hash
      end

      def find_by_name(name)
        attributes.detect {|attribute| attribute.name == name.to_s } || attribute_not_found(name)
      end

      private

      attr_reader :attrs_hash

      class AttributeNotFoundError < StandardError; end

      def attributes
        @attributes ||= attrs_hash.map do |name, value|
          Attribute.new(name, value)
        end
      end

      def attribute_not_found(name)
        raise AttributeNotFoundError, "Attribute '#{name}' is not present."
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
sprig-0.3.1 lib/sprig/seed/attribute_collection.rb
sprig-0.3.0 lib/sprig/seed/attribute_collection.rb
sprig-0.2.0 lib/sprig/seed/attribute_collection.rb
sprig-0.1.9 lib/sprig/seed/attribute_collection.rb
sprig-0.1.7 lib/sprig/seed/attribute_collection.rb
sprig-0.1.6 lib/sprig/seed/attribute_collection.rb
sprig-0.1.5 lib/sprig/seed/attribute_collection.rb
sprig-0.1.4 lib/sprig/seed/attribute_collection.rb
sprig-0.1.3 lib/sprig/seed/attribute_collection.rb
sprig-0.1.2 lib/sprig/seed/attribute_collection.rb
sprig-0.1.1 lib/sprig/seed/attribute_collection.rb
sprig-0.1.0 lib/sprig/seed/attribute_collection.rb