famili 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/famili/father.rb CHANGED
@@ -14,22 +14,39 @@ module Famili
14
14
  def build(opts = {})
15
15
  attributes = merge(opts)
16
16
  model = Famili::Child.new(@mother, attributes).born
17
+ yield model if block_given?
17
18
  @mother.before_save(model)
18
19
  model
19
20
  end
20
21
 
21
- def create(opts = {})
22
- model = build(opts)
22
+ def create(opts = {}, &block)
23
+ model = build(opts, &block)
23
24
  model.save!
24
25
  @mother.after_create(model)
25
26
  model
26
27
  end
27
28
 
29
+ def build_brothers(num, opts = {}, &block)
30
+ brothers = []
31
+ num.times { brothers << build(opts, &block) }
32
+ brothers
33
+ end
34
+
35
+ def create_brothers(num, opts = {}, &block)
36
+ brothers = []
37
+ num.times { brothers << create(opts, &block) }
38
+ brothers
39
+ end
40
+
41
+ def scoped(attributes = {})
42
+ Famili::Father.new(@mother, merge(attributes))
43
+ end
44
+
28
45
  def method_missing(name, *args)
29
46
  if scope_attributes = @mother.class.scopes[name]
30
- Famili::Father.new(@mother, merge(scope_attributes))
47
+ scoped(scope_attributes)
31
48
  else
32
- super
49
+ super(name, *args)
33
50
  end
34
51
  end
35
52
 
data/lib/famili/mother.rb CHANGED
@@ -72,6 +72,18 @@ module Famili
72
72
  father.build_hash(opts)
73
73
  end
74
74
 
75
+ def build_brothers(num, opts = {}, &block)
76
+ father.build_brothers(num, opts, &block)
77
+ end
78
+
79
+ def create_brothers(num, opts = {}, &block)
80
+ father.create_brothers(num, opts, &block)
81
+ end
82
+
83
+ def scoped(attributes = {})
84
+ father.scoped(attributes)
85
+ end
86
+
75
87
  def scope(name)
76
88
  saved_attributes = @attributes
77
89
  @attributes = {}
@@ -1,5 +1,5 @@
1
1
  module Famili
2
2
  module Version
3
- STRING = '0.1.2'
3
+ STRING = '0.1.3'
4
4
  end
5
5
  end
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.2
4
+ version: 0.1.3
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: 2011-10-27 00:00:00.000000000Z
13
+ date: 2011-10-28 00:00:00.000000000Z
14
14
  dependencies: []
15
15
  description: Yet another object mother pattern implementation.
16
16
  email:
@@ -38,7 +38,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
38
38
  version: '0'
39
39
  segments:
40
40
  - 0
41
- hash: 3424676133283759480
41
+ hash: 2274387620902998155
42
42
  required_rubygems_version: !ruby/object:Gem::Requirement
43
43
  none: false
44
44
  requirements:
@@ -50,5 +50,5 @@ rubyforge_project:
50
50
  rubygems_version: 1.8.10
51
51
  signing_key:
52
52
  specification_version: 3
53
- summary: famili-0.1.2
53
+ summary: famili-0.1.3
54
54
  test_files: []