notahat-machinist 0.2.2 → 0.3.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/lib/machinist/active_record.rb +14 -13
- data/lib/machinist.rb +11 -4
- data/lib/sham.rb +4 -0
- metadata +2 -2
@@ -51,13 +51,14 @@ module Machinist
|
|
51
51
|
end
|
52
52
|
|
53
53
|
module ClassMethods
|
54
|
-
def blueprint(&blueprint)
|
55
|
-
@
|
56
|
-
@blueprint
|
54
|
+
def blueprint(name = :master, &blueprint)
|
55
|
+
@blueprints ||= {}
|
56
|
+
@blueprints[name] = blueprint if block_given?
|
57
|
+
@blueprints[name]
|
57
58
|
end
|
58
59
|
|
59
|
-
def make(
|
60
|
-
lathe = Lathe.run(self.new,
|
60
|
+
def make(*args, &block)
|
61
|
+
lathe = Lathe.run(self.new, *args)
|
61
62
|
unless Machinist::ActiveRecord.nerfed?
|
62
63
|
lathe.object.save!
|
63
64
|
lathe.object.reload
|
@@ -65,22 +66,22 @@ module Machinist
|
|
65
66
|
lathe.object(&block)
|
66
67
|
end
|
67
68
|
|
68
|
-
def make_unsaved(
|
69
|
-
returning(Machinist::ActiveRecord.with_save_nerfed { make(
|
69
|
+
def make_unsaved(*args)
|
70
|
+
returning(Machinist::ActiveRecord.with_save_nerfed { make(*args) }) do |object|
|
70
71
|
yield object if block_given?
|
71
72
|
end
|
72
73
|
end
|
73
74
|
|
74
|
-
def plan(
|
75
|
-
lathe = Lathe.run(self.new,
|
75
|
+
def plan(*args)
|
76
|
+
lathe = Lathe.run(self.new, *args)
|
76
77
|
Machinist::ActiveRecord.assigned_attributes_without_associations(lathe)
|
77
78
|
end
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
81
82
|
module BelongsToExtensions
|
82
|
-
def make(
|
83
|
-
lathe = Lathe.run(self.build,
|
83
|
+
def make(*args, &block)
|
84
|
+
lathe = Lathe.run(self.build, *args)
|
84
85
|
unless Machinist::ActiveRecord.nerfed?
|
85
86
|
lathe.object.save!
|
86
87
|
lathe.object.reload
|
@@ -88,8 +89,8 @@ module Machinist
|
|
88
89
|
lathe.object(&block)
|
89
90
|
end
|
90
91
|
|
91
|
-
def plan(
|
92
|
-
lathe = Lathe.run(self.build,
|
92
|
+
def plan(*args)
|
93
|
+
lathe = Lathe.run(self.build, *args)
|
93
94
|
Machinist::ActiveRecord.assigned_attributes_without_associations(lathe)
|
94
95
|
end
|
95
96
|
end
|
data/lib/machinist.rb
CHANGED
@@ -9,10 +9,13 @@ module Machinist
|
|
9
9
|
#
|
10
10
|
# The blueprint is instance_eval'd against the Lathe.
|
11
11
|
class Lathe
|
12
|
-
def self.run(object,
|
13
|
-
blueprint
|
12
|
+
def self.run(object, *args)
|
13
|
+
blueprint = object.class.blueprint
|
14
|
+
named_blueprint = object.class.blueprint(args.shift) if args.first.is_a?(Symbol)
|
15
|
+
attributes = args.pop || {}
|
14
16
|
raise "No blueprint for class #{object.class}" if blueprint.nil?
|
15
17
|
returning self.new(object, attributes) do |lathe|
|
18
|
+
lathe.instance_eval(&named_blueprint) if named_blueprint
|
16
19
|
lathe.instance_eval(&blueprint)
|
17
20
|
end
|
18
21
|
end
|
@@ -52,8 +55,12 @@ module Machinist
|
|
52
55
|
value = if block_given?
|
53
56
|
yield
|
54
57
|
elsif args.empty?
|
55
|
-
|
56
|
-
|
58
|
+
association = @object.class.reflect_on_association(attribute)
|
59
|
+
if association
|
60
|
+
association.class_name.constantize.make(args.first || {})
|
61
|
+
else
|
62
|
+
Sham.send(attribute)
|
63
|
+
end
|
57
64
|
else
|
58
65
|
args.first
|
59
66
|
end
|
data/lib/sham.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notahat-machinist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pete Yandell
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-13 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|