Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Both Factory and Trait have similar methods and interact with a DefinitionProxy. The idea here is to move the interface DefinitionProxy expects to a separate class and both Factory and Trait can delegate to an instance of Definition.
- Loading branch information
1 parent
f721bc6
commit 41bc3ac
Showing
16 changed files
with
243 additions
and
106 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
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,15 @@ | ||
module FactoryGirl | ||
class DeclarationList | ||
def initialize | ||
@definitions = [] | ||
@declarations = [] | ||
end | ||
|
||
def to_attributes | ||
@definitions.inject([]) {|result, definition| result += definition.to_attributes } | ||
@declarations.inject([]) {|result, declaration| result += declaration.to_attributes } | ||
end | ||
|
||
def method_missing(name, *args, &block) | ||
@definitions.send(name, *args, &block) | ||
@declarations.send(name, *args, &block) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module FactoryGirl | ||
class Definition | ||
attr_reader :callbacks, :defined_traits, :attribute_list | ||
|
||
def initialize(name = nil) | ||
@attribute_list = AttributeList.new(name) | ||
@callbacks = [] | ||
@defined_traits = [] | ||
@to_create = nil | ||
end | ||
|
||
delegate :declare_attribute, :to => :attribute_list | ||
|
||
def add_callback(callback) | ||
@callbacks << callback | ||
end | ||
|
||
def to_create(&block) | ||
if block_given? | ||
@to_create = block | ||
else | ||
@to_create | ||
end | ||
end | ||
|
||
def define_trait(trait) | ||
@defined_traits << trait | ||
end | ||
|
||
def trait_by_name(name) | ||
trait_for(name) || FactoryGirl.trait_by_name(name) | ||
end | ||
|
||
private | ||
|
||
def trait_for(name) | ||
defined_traits.detect {|trait| trait.name == name } | ||
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
Oops, something went wrong.