Sha256: ebb332fec82efc3d94123a7e02d0eaafe8a3975344ecbcb73c06f4af82f19fe9

Contents?: true

Size: 987 Bytes

Versions: 37

Compression:

Stored size: 987 Bytes

Contents

module FactoryGirl
  # @api private
  class DeclarationList
    include Enumerable

    def initialize(name = nil)
      @declarations = []
      @name         = name
      @overridable  = false
    end

    def declare_attribute(declaration)
      delete_declaration(declaration) if overridable?

      @declarations << declaration
      declaration
    end

    def overridable
      @overridable = true
    end

    def attributes
      @attributes ||= AttributeList.new(@name).tap do |list|
        to_attributes.each do |attribute|
          list.define_attribute(attribute)
        end
      end
    end

    def each(&block)
      @declarations.each(&block)
    end

    private

    def delete_declaration(declaration)
      @declarations.delete_if {|decl| decl.name == declaration.name }
    end

    def to_attributes
      @declarations.inject([]) {|result, declaration| result += declaration.to_attributes }
    end

    def overridable?
      @overridable
    end
  end
end

Version data entries

37 entries across 28 versions & 4 rubygems

Version Path
factory_girl-4.3.0 lib/factory_girl/declaration_list.rb
challah-1.0.0 vendor/bundle/gems/factory_girl-4.2.0/lib/factory_girl/declaration_list.rb
challah-1.0.0.beta3 vendor/bundle/gems/factory_girl-4.2.0/lib/factory_girl/declaration_list.rb
challah-1.0.0.beta2 vendor/bundle/gems/factory_girl-4.2.0/lib/factory_girl/declaration_list.rb
challah-1.0.0.beta vendor/bundle/gems/factory_girl-4.2.0/lib/factory_girl/declaration_list.rb
challah-1.0.0.beta vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/declaration_list.rb
challah-0.9.1.beta.3 vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/declaration_list.rb
factory_girl-4.2.0 lib/factory_girl/declaration_list.rb
challah-0.9.1.beta vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/declaration_list.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/factory_girl-4.1.0/lib/factory_girl/declaration_list.rb
challah-0.9.0 vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/declaration_list.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/declaration_list.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/factory_girl-3.6.1/lib/factory_girl/declaration_list.rb
challah-rolls-0.2.0 vendor/bundle/gems/factory_girl-4.0.0/lib/factory_girl/declaration_list.rb
challah-rolls-0.2.0 vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/declaration_list.rb
challah-rolls-0.2.0 vendor/bundle/gems/factory_girl-3.6.1/lib/factory_girl/declaration_list.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/factory_girl-4.0.0/lib/factory_girl/declaration_list.rb
challah-0.8.3 vendor/bundle/gems/factory_girl-4.0.0/lib/factory_girl/declaration_list.rb
challah-0.8.3 vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/declaration_list.rb
factory_girl-3.6.2 lib/factory_girl/declaration_list.rb