fabrication 2.5.4 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fabrication/generator/active_record.rb +4 -0
- data/lib/fabrication/generator/base.rb +12 -6
- data/lib/fabrication/generator/data_mapper.rb +5 -0
- data/lib/fabrication/generator/keymaker.rb +4 -0
- data/lib/fabrication/generator/mongoid.rb +4 -0
- data/lib/fabrication/generator/sequel.rb +4 -0
- data/lib/fabrication/schematic/evaluator.rb +26 -0
- data/lib/fabrication/version.rb +1 -1
- metadata +2 -2
@@ -12,23 +12,27 @@ class Fabrication::Generator::Base
|
|
12
12
|
else
|
13
13
|
build_instance
|
14
14
|
end
|
15
|
-
|
16
15
|
execute_callbacks(callbacks[:after_build])
|
17
|
-
|
16
|
+
execute_callbacks(callbacks[:before_validation])
|
17
|
+
validate_instance
|
18
|
+
execute_callbacks(callbacks[:after_validation])
|
18
19
|
__instance
|
19
20
|
end
|
20
21
|
|
21
|
-
def execute_callbacks(callbacks)
|
22
|
-
callbacks.each { |callback| __instance.instance_exec(__instance, __transient_attributes, &callback) } if callbacks
|
23
|
-
end
|
24
|
-
|
25
22
|
def create(attributes=[], callbacks=[])
|
26
23
|
build(attributes, callbacks)
|
24
|
+
execute_callbacks(callbacks[:before_save])
|
25
|
+
execute_callbacks(callbacks[:before_create])
|
27
26
|
persist
|
28
27
|
execute_callbacks(callbacks[:after_create])
|
28
|
+
execute_callbacks(callbacks[:after_save])
|
29
29
|
__instance
|
30
30
|
end
|
31
31
|
|
32
|
+
def execute_callbacks(callbacks)
|
33
|
+
callbacks.each { |callback| __instance.instance_exec(__instance, __transient_attributes, &callback) } if callbacks
|
34
|
+
end
|
35
|
+
|
32
36
|
def to_hash(attributes=[], callbacks=[])
|
33
37
|
process_attributes(attributes)
|
34
38
|
(Fabrication::Config.active_support? ? HashWithIndifferentAccess.new : {}).tap do |hash|
|
@@ -71,6 +75,8 @@ class Fabrication::Generator::Base
|
|
71
75
|
__attributes[method_name] || super
|
72
76
|
end
|
73
77
|
|
78
|
+
def validate_instance; end
|
79
|
+
|
74
80
|
protected
|
75
81
|
|
76
82
|
attr_accessor :__klass, :__instance, :__transient_attributes
|
@@ -8,9 +8,14 @@ class Fabrication::Generator::DataMapper < Fabrication::Generator::Base
|
|
8
8
|
self.__instance = __klass.new(__attributes)
|
9
9
|
end
|
10
10
|
|
11
|
+
def validate_instance
|
12
|
+
__instance.valid?
|
13
|
+
end
|
14
|
+
|
11
15
|
protected
|
12
16
|
|
13
17
|
def persist
|
14
18
|
__instance.save
|
15
19
|
end
|
20
|
+
|
16
21
|
end
|
@@ -13,15 +13,41 @@ class Fabrication::Schematic::Evaluator < BasicObject
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def after_build(&block)
|
16
|
+
::Kernel.puts "DEPRECATION WARNING: after_build callbacks will be removed in fabrication 2.7"
|
16
17
|
@_definition.callbacks[:after_build] ||= []
|
17
18
|
@_definition.callbacks[:after_build] << block
|
18
19
|
end
|
19
20
|
|
21
|
+
def before_validation(&block)
|
22
|
+
@_definition.callbacks[:before_validation] ||= []
|
23
|
+
@_definition.callbacks[:before_validation] << block
|
24
|
+
end
|
25
|
+
|
26
|
+
def after_validation(&block)
|
27
|
+
@_definition.callbacks[:after_validation] ||= []
|
28
|
+
@_definition.callbacks[:after_validation] << block
|
29
|
+
end
|
30
|
+
|
31
|
+
def before_save(&block)
|
32
|
+
@_definition.callbacks[:before_save] ||= []
|
33
|
+
@_definition.callbacks[:before_save] << block
|
34
|
+
end
|
35
|
+
|
36
|
+
def before_create(&block)
|
37
|
+
@_definition.callbacks[:before_create] ||= []
|
38
|
+
@_definition.callbacks[:before_create] << block
|
39
|
+
end
|
40
|
+
|
20
41
|
def after_create(&block)
|
21
42
|
@_definition.callbacks[:after_create] ||= []
|
22
43
|
@_definition.callbacks[:after_create] << block
|
23
44
|
end
|
24
45
|
|
46
|
+
def after_save(&block)
|
47
|
+
@_definition.callbacks[:after_save] ||= []
|
48
|
+
@_definition.callbacks[:after_save] << block
|
49
|
+
end
|
50
|
+
|
25
51
|
def on_init(&block)
|
26
52
|
@_definition.callbacks[:on_init] = block
|
27
53
|
end
|
data/lib/fabrication/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fabrication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|