famili 0.1.9 → 0.1.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/famili/child.rb +3 -2
- data/lib/famili/lazy_value.rb +11 -0
- data/lib/famili/mother.rb +13 -16
- data/lib/famili/version.rb +1 -1
- metadata +6 -5
data/lib/famili/child.rb
CHANGED
@@ -38,9 +38,10 @@ module Famili
|
|
38
38
|
attribute_value = @attributes[name]
|
39
39
|
if attribute_value.is_a?(::Proc)
|
40
40
|
attribute_value = @model.instance_exec(&attribute_value)
|
41
|
-
elsif attribute_value.
|
42
|
-
attribute_value = attribute_value.
|
41
|
+
elsif attribute_value.respond_to?(:call)
|
42
|
+
attribute_value = attribute_value.call
|
43
43
|
end
|
44
|
+
attribute_value = attribute_value.build if attribute_value.is_a?(::Famili::Father)
|
44
45
|
@model.send("#{name}=", attribute_value)
|
45
46
|
end
|
46
47
|
|
data/lib/famili/mother.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'date'
|
2
2
|
require 'famili/father'
|
3
|
+
require "famili/lazy_value"
|
3
4
|
|
4
5
|
module Famili
|
5
6
|
class Mother
|
@@ -37,7 +38,6 @@ module Famili
|
|
37
38
|
|
38
39
|
def inherited(child)
|
39
40
|
child.parent_class = self
|
40
|
-
child.pending_tasks = []
|
41
41
|
end
|
42
42
|
|
43
43
|
def name(&block)
|
@@ -59,16 +59,19 @@ module Famili
|
|
59
59
|
attributes[method] = block
|
60
60
|
end
|
61
61
|
|
62
|
+
def lazy(&block)
|
63
|
+
Famili::LazyValue.new(&block)
|
64
|
+
end
|
65
|
+
|
62
66
|
def has(name, &block)
|
63
|
-
|
67
|
+
attributes[name] = lazy do
|
64
68
|
father = "#{model_class.reflect_on_association(name.to_sym).klass.name}Famili".constantize.new_father
|
65
69
|
father = father.scoped(collect_attributes(&block)) if block_given?
|
66
|
-
|
67
|
-
end
|
70
|
+
father
|
71
|
+
end
|
68
72
|
end
|
69
73
|
|
70
74
|
def new_father
|
71
|
-
invoke_pending_tasks if pending_tasks
|
72
75
|
Famili::Father.new(self.new, attributes)
|
73
76
|
end
|
74
77
|
|
@@ -85,7 +88,7 @@ module Famili
|
|
85
88
|
|
86
89
|
def model_class(klass = nil)
|
87
90
|
if klass
|
88
|
-
|
91
|
+
self.model_class = klass
|
89
92
|
return
|
90
93
|
end
|
91
94
|
|
@@ -96,18 +99,12 @@ module Famili
|
|
96
99
|
end
|
97
100
|
end
|
98
101
|
|
99
|
-
|
100
|
-
|
101
|
-
attr_accessor :pending_tasks
|
102
|
-
|
103
|
-
def invoke_pending_tasks
|
104
|
-
parent_class.invoke_pending_tasks if parent_class
|
105
|
-
if @pending_tasks
|
106
|
-
@pending_tasks.each(&:call)
|
107
|
-
@pending_tasks = nil
|
108
|
-
end
|
102
|
+
def model_class=(klass)
|
103
|
+
@model_class = klass
|
109
104
|
end
|
110
105
|
|
106
|
+
protected
|
107
|
+
|
111
108
|
def collect_attributes
|
112
109
|
saved_attributes, @attributes = @attributes, {}
|
113
110
|
yield
|
data/lib/famili/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: famili
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.9
|
4
|
+
version: 0.1.9.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-07-
|
13
|
+
date: 2012-07-03 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: Yet another object mother pattern implementation.
|
16
16
|
email:
|
@@ -21,6 +21,7 @@ files:
|
|
21
21
|
- lib/famili.rb
|
22
22
|
- lib/famili/child.rb
|
23
23
|
- lib/famili/father.rb
|
24
|
+
- lib/famili/lazy_value.rb
|
24
25
|
- lib/famili/mother.rb
|
25
26
|
- lib/famili/version.rb
|
26
27
|
homepage: http://github.com/niquola/famili
|
@@ -38,7 +39,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
39
|
version: '0'
|
39
40
|
segments:
|
40
41
|
- 0
|
41
|
-
hash:
|
42
|
+
hash: -1932633742867940772
|
42
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
44
|
none: false
|
44
45
|
requirements:
|
@@ -47,11 +48,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
48
|
version: '0'
|
48
49
|
segments:
|
49
50
|
- 0
|
50
|
-
hash:
|
51
|
+
hash: -1932633742867940772
|
51
52
|
requirements: []
|
52
53
|
rubyforge_project:
|
53
54
|
rubygems_version: 1.8.10
|
54
55
|
signing_key:
|
55
56
|
specification_version: 3
|
56
|
-
summary: famili-0.1.9
|
57
|
+
summary: famili-0.1.9.1
|
57
58
|
test_files: []
|