Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DeclarationList knows how to generate an attribute list, which never really made sense outside of being generated from declarations. Now, the declaration list builds a list of attributes which is combined in Factory#attributes with attributes from traits and its parents.
- Loading branch information
1 parent
0124d42
commit 3114dcd
Showing
12 changed files
with
146 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,48 @@ | ||
module FactoryGirl | ||
class DeclarationList | ||
def initialize | ||
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 attribute_list | ||
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 method_missing(name, *args, &block) | ||
@declarations.send(name, *args, &block) | ||
def overridable? | ||
@overridable | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.