creators 0.9 → 0.91

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- creators (0.9)
4
+ creators (0.91)
5
5
  rails
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Creators 0.9 [![Build Status](https://secure.travis-ci.org/TheGiftsProject/Creators.png)](http://travis-ci.org/TheGiftsProject/Creators)
1
+ # Creators 0.91 [![Build Status](https://secure.travis-ci.org/TheGiftsProject/Creators.png)](http://travis-ci.org/TheGiftsProject/Creators)
2
2
 
3
3
  Creators help to clean up your controllers from the model creation setup code.
4
4
  For the most basic situations simply creating a Creator and passing into it the request params, will just work for
@@ -35,7 +35,10 @@ end
35
35
  ## Defining a creator
36
36
 
37
37
  We recommend putting all your creator objects in `app/creators`.
38
+
38
39
  The model class that's attached to the creator is deduced from the name of the class.
40
+ You can override this behavior by adding a `model` definition to the creator (`model 'AnotherModel'`).
41
+
39
42
 
40
43
  ```ruby
41
44
  class ProjectCreator < Creators::Base
@@ -76,7 +79,7 @@ The specific behavior of your Creator is defined in the `refine_params` method a
76
79
  the Save method Life Cycle. The Creator `save` method is divided into 2 main steps:
77
80
 
78
81
  1) `build` - This step simply instantiates a new model (Project in our example) and assigns to it the `raw_params` we've
79
- passed to the Creator. The `refine_params` step by default just uses the `raw_params`, and it can be easily overrided by
82
+ passed to the Creator. The `refine_params` step by default just uses the `raw_params`, and it can be easily overridden by
80
83
  using the `refine_params` method. (As shown in our example)
81
84
  Callback methods: `before_build`, `after_build`
82
85
 
@@ -125,6 +128,7 @@ class TaskCreator < Creators::Base
125
128
  end
126
129
 
127
130
  end
131
+ ```
128
132
 
129
133
  For update operations, if you pass to super a model as the 2nd argument, then that model will be used
130
134
  in the build process instead of it creating a new one, in case that model isn't nil.
@@ -27,13 +27,17 @@ module Creators
27
27
  def self.inherited(child_class)
28
28
  child_class.class_eval do
29
29
  class_name = child_class.to_s.gsub('Creator', '')
30
- define_method :klass do
31
- class_name.constantize
32
- end
30
+ self.model(class_name)
31
+ end
32
+ end
33
+
34
+ def self.model(class_name)
35
+ define_method :klass do
36
+ class_name.constantize
37
+ end
33
38
 
34
- define_method class_name.underscore do
35
- model
36
- end
39
+ define_method class_name.underscore do
40
+ model
37
41
  end
38
42
  end
39
43
 
@@ -1,3 +1,3 @@
1
1
  module Creators
2
- VERSION = 0.9
2
+ VERSION = 0.91
3
3
  end
@@ -31,11 +31,29 @@ describe Creators::Base do
31
31
  end
32
32
  end
33
33
 
34
+ class AnotherFakeModel
35
+ end
36
+
34
37
  class FakeModelCreator < Creators::Base
35
38
  end
36
39
 
40
+ class AnotherFakeModelCreator < Creators::Base
41
+ model 'FakeModel'
42
+ end
43
+
37
44
  subject { FakeModelCreator.new }
38
45
 
46
+ describe 'self.model' do
47
+
48
+ let(:another_creator) { AnotherFakeModelCreator.new }
49
+
50
+ it 'should override the target model of the Creator (which is implied from the Creator name)' do
51
+ another_creator.klass.should == FakeModel
52
+ another_creator.klass.should_not == AnotherFakeModel
53
+ end
54
+
55
+ end
56
+
39
57
  describe :save do
40
58
 
41
59
  context 'params are invalid' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: creators
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.9'
4
+ version: '0.91'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-11-14 00:00:00.000000000Z
14
+ date: 2012-11-26 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
18
- requirement: &24302960 !ruby/object:Gem::Requirement
18
+ requirement: !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,15 @@ dependencies:
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *24302960
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: rake
29
- requirement: &24302540 !ruby/object:Gem::Requirement
34
+ requirement: !ruby/object:Gem::Requirement
30
35
  none: false
31
36
  requirements:
32
37
  - - ! '>='
@@ -34,10 +39,15 @@ dependencies:
34
39
  version: '0'
35
40
  type: :development
36
41
  prerelease: false
37
- version_requirements: *24302540
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
38
48
  - !ruby/object:Gem::Dependency
39
49
  name: rspec
40
- requirement: &24302120 !ruby/object:Gem::Requirement
50
+ requirement: !ruby/object:Gem::Requirement
41
51
  none: false
42
52
  requirements:
43
53
  - - ! '>='
@@ -45,7 +55,12 @@ dependencies:
45
55
  version: '0'
46
56
  type: :development
47
57
  prerelease: false
48
- version_requirements: *24302120
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
49
64
  description: ! 'Creators are used to host code dealing with creation of new models
50
65
  and clean up the controllers. '
51
66
  email:
@@ -89,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
104
  version: '0'
90
105
  requirements: []
91
106
  rubyforge_project:
92
- rubygems_version: 1.8.17
107
+ rubygems_version: 1.8.24
93
108
  signing_key:
94
109
  specification_version: 3
95
110
  summary: Making it even nicer to manage Form data params in your Controller.