blueprints 0.9.0 → 1.0.0
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/.gitignore +1 -0
- data/Gemfile +14 -1
- data/README.rdoc +3 -173
- data/Rakefile +32 -15
- data/blueprints.gemspec +2 -16
- data/lib/blueprints.rb +17 -10
- data/lib/blueprints/blueprint.rb +85 -41
- data/lib/blueprints/blueprint_name_proxy.rb +34 -0
- data/lib/blueprints/buildable.rb +53 -26
- data/lib/blueprints/context.rb +8 -0
- data/lib/blueprints/extensions.rb +22 -4
- data/lib/blueprints/extensions/rspec.rb +28 -14
- data/lib/blueprints/helper.rb +17 -9
- data/lib/blueprints/namespace.rb +20 -14
- data/lib/blueprints/railtie.rb +3 -0
- data/lib/blueprints/root_namespace.rb +16 -23
- data/lib/blueprints/version.rb +1 -1
- data/lib/generators/blueprints/model/model_generator.rb +29 -0
- data/spec/blueprints_spec.rb +18 -1
- data/spec/support/active_record/initializer.rb +9 -5
- data/spec/support/none/initializer.rb +4 -0
- data/spec/unit/active_record_spec.rb +58 -4
- data/spec/unit/blueprint_name_proxy_spec.rb +31 -0
- data/spec/unit/blueprint_spec.rb +160 -22
- data/spec/unit/blueprints_spec.rb +4 -4
- data/spec/unit/context_spec.rb +8 -1
- data/spec/unit/dependency_spec.rb +1 -5
- data/spec/unit/fixtures.rb +69 -47
- data/spec/unit/namespace_spec.rb +23 -5
- data/spec/unit/root_namespace_spec.rb +9 -0
- data/spec/unit/spec_helper.rb +3 -4
- data/test/blueprints_test.rb +18 -1
- data/test/test_helper.rb +1 -0
- data/test_all.sh +6 -33
- metadata +43 -276
- data/Gemfile.lock +0 -108
- data/lib/blueprints/database_cleaner_fix.rb +0 -9
- data/lib/blueprints/eval_context.rb +0 -51
- data/spec/unit/eval_context_spec.rb +0 -56
data/Gemfile.lock
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
blueprints (0.8.2)
|
5
|
-
activesupport (>= 2.3.0)
|
6
|
-
database_cleaner (~> 0.5.0)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: http://rubygems.org/
|
10
|
-
specs:
|
11
|
-
activemodel (3.0.3)
|
12
|
-
activesupport (= 3.0.3)
|
13
|
-
builder (~> 2.1.2)
|
14
|
-
i18n (~> 0.4)
|
15
|
-
activerecord (3.0.3)
|
16
|
-
activemodel (= 3.0.3)
|
17
|
-
activesupport (= 3.0.3)
|
18
|
-
arel (~> 2.0.2)
|
19
|
-
tzinfo (~> 0.3.23)
|
20
|
-
activesupport (3.0.3)
|
21
|
-
addressable (2.2.2)
|
22
|
-
arel (2.0.6)
|
23
|
-
bson (1.1.4)
|
24
|
-
bson_ext (1.1.4)
|
25
|
-
builder (2.1.2)
|
26
|
-
cucumber (0.9.4)
|
27
|
-
builder (~> 2.1.2)
|
28
|
-
diff-lcs (~> 1.1.2)
|
29
|
-
gherkin (~> 2.2.9)
|
30
|
-
json (~> 1.4.6)
|
31
|
-
term-ansicolor (~> 1.0.5)
|
32
|
-
data_objects (0.10.2)
|
33
|
-
addressable (~> 2.1)
|
34
|
-
database_cleaner (0.5.2)
|
35
|
-
diff-lcs (1.1.2)
|
36
|
-
dm-core (1.0.2)
|
37
|
-
addressable (~> 2.2)
|
38
|
-
extlib (~> 0.9.15)
|
39
|
-
dm-do-adapter (1.0.2)
|
40
|
-
data_objects (~> 0.10.2)
|
41
|
-
dm-core (~> 1.0.2)
|
42
|
-
dm-migrations (1.0.2)
|
43
|
-
dm-core (~> 1.0.2)
|
44
|
-
dm-mysql-adapter (1.0.2)
|
45
|
-
dm-do-adapter (~> 1.0.2)
|
46
|
-
do_mysql (~> 0.10.2)
|
47
|
-
dm-transactions (1.0.2)
|
48
|
-
dm-core (~> 1.0.2)
|
49
|
-
do_mysql (0.10.2)
|
50
|
-
data_objects (= 0.10.2)
|
51
|
-
extlib (0.9.15)
|
52
|
-
gherkin (2.2.9)
|
53
|
-
json (~> 1.4.6)
|
54
|
-
term-ansicolor (~> 1.0.5)
|
55
|
-
i18n (0.5.0)
|
56
|
-
jnunemaker-validatable (1.8.4)
|
57
|
-
activesupport (>= 2.3.4)
|
58
|
-
json (1.4.6)
|
59
|
-
mocha (0.9.10)
|
60
|
-
rake
|
61
|
-
mongo (1.1.4)
|
62
|
-
bson (>= 1.1.1)
|
63
|
-
mongo_mapper (0.8.6)
|
64
|
-
activesupport (>= 2.3.4)
|
65
|
-
jnunemaker-validatable (~> 1.8.4)
|
66
|
-
plucky (~> 0.3.6)
|
67
|
-
mongoid (2.0.0.beta.20)
|
68
|
-
activemodel (~> 3.0)
|
69
|
-
mongo (~> 1.1)
|
70
|
-
tzinfo (~> 0.3.22)
|
71
|
-
will_paginate (~> 3.0.pre)
|
72
|
-
mysql2 (0.2.6)
|
73
|
-
plucky (0.3.6)
|
74
|
-
mongo (~> 1.1)
|
75
|
-
rake (0.8.7)
|
76
|
-
rspec (2.2.0)
|
77
|
-
rspec-core (~> 2.2)
|
78
|
-
rspec-expectations (~> 2.2)
|
79
|
-
rspec-mocks (~> 2.2)
|
80
|
-
rspec-core (2.2.1)
|
81
|
-
rspec-expectations (2.2.0)
|
82
|
-
diff-lcs (~> 1.1.2)
|
83
|
-
rspec-mocks (2.2.0)
|
84
|
-
shoulda (2.11.3)
|
85
|
-
term-ansicolor (1.0.5)
|
86
|
-
tzinfo (0.3.23)
|
87
|
-
will_paginate (3.0.pre2)
|
88
|
-
|
89
|
-
PLATFORMS
|
90
|
-
ruby
|
91
|
-
|
92
|
-
DEPENDENCIES
|
93
|
-
activerecord (>= 2.3.0)
|
94
|
-
activesupport (>= 2.3.0)
|
95
|
-
blueprints!
|
96
|
-
bson_ext (>= 1.1.4)
|
97
|
-
bundler (>= 1.0.0)
|
98
|
-
cucumber (>= 0.7.0)
|
99
|
-
database_cleaner (~> 0.5.0)
|
100
|
-
dm-migrations (>= 1.0.0)
|
101
|
-
dm-mysql-adapter (>= 1.0.0)
|
102
|
-
dm-transactions (>= 1.0.0)
|
103
|
-
mocha (>= 0.9.8)
|
104
|
-
mongo_mapper (>= 0.8.0)
|
105
|
-
mongoid (>= 2.0.0.beta)
|
106
|
-
mysql2
|
107
|
-
rspec (~> 2.2.0)
|
108
|
-
shoulda (>= 2.10.0)
|
@@ -1,51 +0,0 @@
|
|
1
|
-
module Blueprints
|
2
|
-
class EvalContext
|
3
|
-
# Copy instance variables to another object.
|
4
|
-
# @param target Object to copy instance variables to.
|
5
|
-
def copy_instance_variables(target)
|
6
|
-
instance_variables.each do |iv_name|
|
7
|
-
target.instance_variable_set(iv_name, instance_variable_get(iv_name))
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
# Sets options and attributes and evaluates block against self.
|
12
|
-
# @param [Blueprints::Context] context Context of buildable object. Used to extract attributes.
|
13
|
-
# @param [Hash] options Options hash, merged into attributes.
|
14
|
-
def instance_eval(context, options, &block)
|
15
|
-
options = normalize_hash(options)
|
16
|
-
define_singleton_method(:options) { options }
|
17
|
-
attributes = normalize_hash(context.attributes).merge(options)
|
18
|
-
define_singleton_method(:attributes) { attributes }
|
19
|
-
|
20
|
-
super(&block)
|
21
|
-
end
|
22
|
-
|
23
|
-
# Builds blueprints by delegating to root namespace.
|
24
|
-
# @param [Array<String, Symbol>] blueprints Names of buildables.
|
25
|
-
# @return Result of last buildable.
|
26
|
-
def build(*blueprints)
|
27
|
-
Namespace.root.build(blueprints)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Normalizes attributes hash by evaluating all Proc and Blueprints::Dependency objects against itself.
|
31
|
-
# @param [Hash] hash Attributes hash.
|
32
|
-
# @return [Hash] Normalized hash.
|
33
|
-
def normalize_hash(hash)
|
34
|
-
hash.each_with_object({}) do |(attr, value), normalized|
|
35
|
-
normalized[attr] = if value.respond_to?(:to_proc) and not Symbol === value
|
36
|
-
instance_exec(&value)
|
37
|
-
else
|
38
|
-
value
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def define_singleton_method(name, &block)
|
46
|
-
singleton_class.class_eval do
|
47
|
-
define_method(name, &block)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe Blueprints::EvalContext do
|
4
|
-
subject do
|
5
|
-
Blueprints::EvalContext.new
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should contain no instance variables" do
|
9
|
-
subject.instance_variables.should == []
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "instance variables" do
|
13
|
-
it "should allow copying variables to other context" do
|
14
|
-
subject.instance_variable_set(:@var, :value)
|
15
|
-
subject.copy_instance_variables(context = Object.new)
|
16
|
-
context.instance_variables.collect(&:to_sym).should == [:@var]
|
17
|
-
context.instance_variable_get(:@var).should == :value
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "instance eval" do
|
22
|
-
subject do
|
23
|
-
Blueprints::EvalContext.new
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should allow to access to options" do
|
27
|
-
subject.instance_eval(context, :option => 'value') do
|
28
|
-
options.should == {:option => 'value'}
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should allow to access to attributes" do
|
33
|
-
subject.instance_eval(context_with_attrs_and_deps, :option => 'value') do
|
34
|
-
attributes.should == {:option => 'value', :attr1 => 1, :attr2 => 2}
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should normalize options and attributes" do
|
39
|
-
blueprint.build(subject)
|
40
|
-
subject.instance_variable_set(:@value, 2)
|
41
|
-
context = Blueprints::Context.new(:attributes => {:attr => Blueprints::Dependency.new(:blueprint)})
|
42
|
-
|
43
|
-
subject.instance_eval(context, :attr2 => lambda { @value + 2 }, :attr3 => :value) do
|
44
|
-
options.should == {:attr2 => 4, :attr3 => :value}
|
45
|
-
attributes.should == {:attr => @blueprint, :attr2 => 4, :attr3 => :value}
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "build" do
|
51
|
-
it "should allow building blueprint" do
|
52
|
-
blueprint
|
53
|
-
subject.build(:blueprint).should == mock1
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|