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 +1 -1
- data/README.md +6 -2
- data/lib/creators/creator.rb +10 -6
- data/lib/creators/version.rb +1 -1
- data/spec/lib/creators/creator_spec.rb +18 -0
- metadata +24 -9
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Creators 0.
|
1
|
+
# Creators 0.91 [](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
|
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.
|
data/lib/creators/creator.rb
CHANGED
@@ -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
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
35
|
-
|
36
|
-
end
|
39
|
+
define_method class_name.underscore do
|
40
|
+
model
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
data/lib/creators/version.rb
CHANGED
@@ -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.
|
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
|
+
date: 2012-11-26 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
18
|
-
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:
|
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:
|
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:
|
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:
|
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:
|
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.
|
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.
|