blueprints 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.6.1
data/blueprints.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{blueprints}
8
- s.version = "0.6.0"
8
+ s.version = "0.6.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrius Chamentauskas"]
12
- s.date = %q{2010-05-25}
12
+ s.date = %q{2010-05-28}
13
13
  s.description = %q{Another replacement for factories and fixtures. The library that lazy typists will love}
14
14
  s.email = %q{sinsiliux@gmail.com}
15
15
  s.extra_rdoc_files = [
data/lib/blueprints.rb CHANGED
@@ -78,16 +78,20 @@ module Blueprints
78
78
 
79
79
  # Loads blueprints file and creates blueprints from data it contains. Is run by setup method
80
80
  def self.load_scenarios_files(*patterns)
81
+ FileContext.evaluating = true
82
+
81
83
  patterns.flatten!
82
84
  patterns.collect! {|pattern| File.join(framework_root, pattern)} if framework_root
83
85
 
84
86
  patterns.each do |pattern|
85
87
  unless (files = Dir.glob(pattern)).empty?
86
88
  files.each{|f| FileContext.module_eval File.read(f)}
89
+ FileContext.evaluating = false
87
90
  return
88
91
  end
89
92
  end
90
93
 
94
+ FileContext.evaluating = false
91
95
  raise "Plans file not found! Put plans in #{patterns.join(' or ')} or pass custom filename pattern with :filename option"
92
96
  end
93
97
  end
@@ -57,18 +57,17 @@ module Blueprints
57
57
  # Post.blueprint(:post, :title => 'first post', :text => 'My first post', :user => :@user).depends_on(:user)
58
58
  # or like this:
59
59
  # Post.blueprint({:post => :user}, :title => 'first post', :text => 'My first post', :user => :@user)
60
- def blueprint(*args)
61
- attrs = args.pop
62
- if args.present?
60
+ def blueprint(name_or_attrs, attrs = {})
61
+ if Blueprints::FileContext.evaluating
63
62
  klass = self
64
- blueprint = Blueprints::Plan.new(*args) { klass.blueprint attributes }
63
+ blueprint = Blueprints::Plan.new(name_or_attrs) { klass.blueprint attributes }
65
64
  blueprint.depends_on(*attrs.values.select {|attr| attr.is_a?(Blueprints::Buildable::Dependency) }).attributes(attrs)
66
65
  blueprint
67
66
  else
68
- if attrs.is_a?(Array)
69
- attrs.collect { |attr| blueprint(attr) }
67
+ if name_or_attrs.is_a?(Array)
68
+ name_or_attrs.collect { |attrs| blueprint(attrs) }
70
69
  else
71
- returning(self.new) { |object| object.blueprint(attrs) }
70
+ returning(self.new) { |object| object.blueprint(name_or_attrs) }
72
71
  end
73
72
  end
74
73
  end
@@ -1,6 +1,8 @@
1
1
  module Blueprints
2
2
  # Module that blueprints file is executed against. Defined <tt>blueprint</tt> and <tt>namespace</tt> methods.
3
3
  module FileContext
4
+ mattr_accessor :evaluating
5
+
4
6
  # Creates a new plan by name and block passed
5
7
  def self.blueprint(plan, &block)
6
8
  Plan.new(plan, &block)
@@ -36,6 +36,7 @@ blueprint :parent_not_existing => :not_existing
36
36
 
37
37
  Tree.blueprint :oak, :name => 'Oak', :size => 'large'
38
38
  blueprint(:huge_oak).extends(:oak, :size => 'huge')
39
+ Tree.blueprint(:oak_without_attributes)
39
40
 
40
41
  blueprint :pine do
41
42
  @the_pine = Tree.blueprint :name => 'Pine', :size => 'medium'
@@ -264,6 +264,11 @@ describe Blueprints do
264
264
  fruits = Fruit.blueprint([{:species => 'fruit1'}, {:species => 'fruit2'}])
265
265
  fruits.collect(&:species).should == %w{fruit1 fruit2}
266
266
  end
267
+
268
+ it "should allow to build oak without attributes" do
269
+ build :oak_without_attributes
270
+ @oak_without_attributes.should be_instance_of(Tree)
271
+ end
267
272
  end
268
273
 
269
274
  describe "with pitted namespace" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blueprints
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 0
10
- version: 0.6.0
9
+ - 1
10
+ version: 0.6.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrius Chamentauskas
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-25 00:00:00 +03:00
18
+ date: 2010-05-28 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies: []
21
21