zertico 1.3.0 → 2.0.0.alpha.1
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.hound.yml +17 -0
- data/.travis.yml +36 -23
- data/CHANGELOG.md +103 -0
- data/README.md +39 -19
- data/gemfiles/Gemfile.rails3-ruby1.8.7 +7 -0
- data/gemfiles/Gemfile.rails3-ruby1.9.2+ +6 -0
- data/gemfiles/Gemfile.rails4-ruby1.9.2+ +5 -0
- data/lib/zertico.rb +1 -0
- data/lib/zertico/controller.rb +24 -16
- data/lib/zertico/delegator.rb +12 -5
- data/lib/zertico/exceptions.rb +1 -0
- data/lib/zertico/exceptions/missing_strong_parameters.rb +9 -0
- data/lib/zertico/interactor.rb +15 -2
- data/lib/zertico/organizer.rb +7 -5
- data/lib/zertico/permitted_params.rb +21 -0
- data/lib/zertico/responder.rb +16 -31
- data/lib/zertico/responder/force_redirect.rb +34 -0
- data/lib/zertico/responder/pjax.rb +13 -0
- data/lib/zertico/service.rb +5 -62
- data/lib/zertico/service/class_methods.rb +29 -0
- data/lib/zertico/service/instance_methods.rb +60 -0
- data/lib/zertico/version.rb +1 -1
- data/spec/fake_app/app/controllers/admin/user_controller.rb +6 -0
- data/spec/fake_app/app/controllers/application_controller.rb +7 -0
- data/spec/fake_app/app/controllers/person/gifts_controller.rb +6 -0
- data/spec/fake_app/app/controllers/person/profile_controller.rb +6 -0
- data/spec/fake_app/app/controllers/user_controller.rb +2 -0
- data/spec/fake_app/app/controllers/users_controller.rb +7 -0
- data/spec/fake_app/{delegators → app/delegators}/admin/user_delegator.rb +0 -0
- data/spec/fake_app/{delegators → app/delegators}/profile/profile_delegator.rb +0 -0
- data/spec/fake_app/{delegators → app/delegators}/user_delegator.rb +0 -0
- data/spec/fake_app/{interactors → app/interactors}/create_invoice_interactor.rb +0 -0
- data/spec/fake_app/{interactors → app/interactors}/create_product_interactor.rb +0 -0
- data/spec/fake_app/{interactors → app/interactors}/create_user_interactor.rb +0 -0
- data/spec/fake_app/{interactors → app/interactors}/send_welcome_email_interactor.rb +0 -0
- data/spec/fake_app/{interfaces → app/interfaces}/invoice.rb +0 -0
- data/spec/fake_app/{interfaces → app/interfaces}/person/profile.rb +0 -0
- data/spec/fake_app/{interfaces → app/interfaces}/product.rb +0 -0
- data/spec/fake_app/app/interfaces/user.rb +32 -0
- data/spec/fake_app/{organizers → app/organizers}/buy_product_organizer.rb +0 -0
- data/spec/fake_app/{organizers → app/organizers}/register_organizer.rb +0 -0
- data/spec/fake_app/app/permitted_params/users_permitted_params.rb +9 -0
- data/spec/fake_app/app/responders/users_responder.rb +5 -0
- data/spec/fake_app/app/services/admin/user_service.rb +6 -0
- data/spec/fake_app/app/services/person/gifts_service.rb +4 -0
- data/spec/fake_app/app/services/person/profile_service.rb +4 -0
- data/spec/fake_app/app/services/user_service.rb +5 -0
- data/spec/fake_app/app/services/users_service.rb +3 -0
- data/spec/fake_app/app/views/layouts/application.html.erb +1 -0
- data/spec/fake_app/app/views/users/edit.html.erb +0 -0
- data/spec/fake_app/app/views/users/index.html.erb +0 -0
- data/spec/fake_app/app/views/users/new.html.erb +0 -0
- data/spec/fake_app/app/views/users/show.html.erb +0 -0
- data/spec/fake_app/config/application.rb +10 -0
- data/spec/fake_app/config/routes.rb +3 -0
- data/spec/fake_app/config/secrets.yml +4 -0
- data/spec/spec_helper.rb +17 -3
- data/spec/zertico/controller_integration_spec.rb +92 -0
- data/spec/zertico/controller_spec.rb +14 -151
- data/spec/zertico/delegator_spec.rb +60 -11
- data/spec/zertico/interactor_spec.rb +41 -1
- data/spec/zertico/organizer_spec.rb +21 -4
- data/spec/zertico/permitted_params_spec.rb +25 -0
- data/spec/zertico/responder_spec.rb +234 -0
- data/spec/zertico/service/class_methods_spec.rb +36 -0
- data/spec/zertico/service/instance_methods_spec.rb +218 -0
- data/zertico.gemspec +10 -2
- metadata +139 -55
- data/gemfiles/Gemfile.rails3.1 +0 -5
- data/gemfiles/Gemfile.rails3.2 +0 -5
- data/gemfiles/Gemfile.rails4.0 +0 -5
- data/gemfiles/Gemfile.rails4.1 +0 -5
- data/spec/fake_app/controllers/admin/user_controller.rb +0 -4
- data/spec/fake_app/controllers/profile/profile_controller.rb +0 -4
- data/spec/fake_app/controllers/user_controller.rb +0 -2
- data/spec/fake_app/controllers/users_controller.rb +0 -2
- data/spec/fake_app/interfaces/user.rb +0 -9
- data/spec/fake_app/services/admin/user_service.rb +0 -8
- data/spec/fake_app/services/person/profile_service.rb +0 -5
- data/spec/fake_app/services/user_service.rb +0 -6
- data/spec/zertico/service_spec.rb +0 -162
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 612a9f684881747d1a85ca57c61e15ee06e2b9ca
|
4
|
+
data.tar.gz: 09f94e32870ed318a59852e560ede7816026c4ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9edf88ad4dbe5c8a8c48ec01e2b02b776c62a35345e60444ea8adba06b7278be112ef2c8b8b629641263ccca771000c61a2d710288c2fe5feb9981aac2117655
|
7
|
+
data.tar.gz: a07da191a75726a209a6cc15bb0eecb51caa7dca8a16ccff860eeb4805f1f229f6b0681abb4c043a987b10c58b950e21218fb10ab0371fd758596fe0ba953404
|
data/.gitignore
CHANGED
data/.hound.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
MethodCalledOnDoEndBlock:
|
2
|
+
Enabled: true
|
3
|
+
|
4
|
+
Metrics/LineLength:
|
5
|
+
Max: 100
|
6
|
+
|
7
|
+
Style/HashSyntax:
|
8
|
+
EnforcedStyle: hash_rockets
|
9
|
+
|
10
|
+
Style/TrailingWhitespace:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Style/SpaceInsideBrackets:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/SymbolArray:
|
17
|
+
Enabled: true
|
data/.travis.yml
CHANGED
@@ -1,27 +1,40 @@
|
|
1
|
-
rvm:
|
2
|
-
- 1.8.7
|
3
|
-
- 1.9.2
|
4
|
-
- 1.9.3
|
5
|
-
- 2.0.0
|
6
|
-
- 2.1.1
|
7
|
-
- ree
|
8
|
-
- jruby
|
9
|
-
gemfile:
|
10
|
-
- gemfiles/Gemfile.rails3.1
|
11
|
-
- gemfiles/Gemfile.rails3.2
|
12
|
-
- gemfiles/Gemfile.rails4.0
|
13
|
-
- gemfiles/Gemfile.rails4.1
|
14
1
|
matrix:
|
15
|
-
|
2
|
+
include:
|
16
3
|
- rvm: 1.8.7
|
17
|
-
gemfile: gemfiles/Gemfile.
|
18
|
-
- rvm: ree
|
19
|
-
gemfile: gemfiles/Gemfile.rails4.0
|
4
|
+
gemfile: gemfiles/Gemfile.rails3-ruby1.8.7
|
20
5
|
- rvm: 1.9.2
|
21
|
-
gemfile: gemfiles/Gemfile.
|
22
|
-
|
23
|
-
|
6
|
+
gemfile: gemfiles/Gemfile.rails3-ruby1.9.2+
|
7
|
+
env: COVERAGE=true
|
8
|
+
- rvm: 1.9.3
|
9
|
+
gemfile: gemfiles/Gemfile.rails3-ruby1.9.2+
|
10
|
+
env: COVERAGE=true
|
11
|
+
- rvm: 1.9.3
|
12
|
+
gemfile: gemfiles/Gemfile.rails4-ruby1.9.2+
|
13
|
+
env: COVERAGE=true
|
14
|
+
- rvm: 2.0.0
|
15
|
+
gemfile: gemfiles/Gemfile.rails3-ruby1.9.2+
|
16
|
+
env: COVERAGE=true
|
17
|
+
- rvm: 2.0.0
|
18
|
+
gemfile: gemfiles/Gemfile.rails4-ruby1.9.2+
|
19
|
+
env: COVERAGE=true
|
20
|
+
- rvm: 2.1.2
|
21
|
+
gemfile: gemfiles/Gemfile.rails3-ruby1.9.2+
|
22
|
+
env: COVERAGE=true
|
23
|
+
- rvm: 2.1.2
|
24
|
+
gemfile: gemfiles/Gemfile.rails4-ruby1.9.2+
|
25
|
+
env: COVERAGE=true
|
24
26
|
- rvm: ree
|
25
|
-
gemfile: gemfiles/Gemfile.
|
26
|
-
- rvm:
|
27
|
-
gemfile: gemfiles/Gemfile.
|
27
|
+
gemfile: gemfiles/Gemfile.rails3-ruby1.8.7
|
28
|
+
- rvm: jruby
|
29
|
+
gemfile: gemfiles/Gemfile.rails3-ruby1.9.2+
|
30
|
+
env: COVERAGE=true
|
31
|
+
- rvm: jruby
|
32
|
+
gemfile: gemfiles/Gemfile.rails4-ruby1.9.2+
|
33
|
+
env: COVERAGE=true
|
34
|
+
notifications:
|
35
|
+
webhooks:
|
36
|
+
urls:
|
37
|
+
- https://webhooks.gitter.im/e/edaa9e7b8d7812636188
|
38
|
+
on_success: always # options: [always|never|change] default: always
|
39
|
+
on_failure: always # options: [always|never|change] default: always
|
40
|
+
on_start: true # default: false
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
## master
|
4
|
+
|
5
|
+
* Changed Service to class. Exposed api methods to use instead of overwrite methods.
|
6
|
+
* Fixed some bugs.
|
7
|
+
* Improved Delegator, Interactor, Organizer.
|
8
|
+
|
9
|
+
## v1.3.0
|
10
|
+
|
11
|
+
* Deprecated Accessor in favor of Delegator.
|
12
|
+
* Created Delegator.
|
13
|
+
* Created Interactor and Organizer.
|
14
|
+
|
15
|
+
## v1.2.0
|
16
|
+
|
17
|
+
* Added ruby 1.8.7, 1.9.2, 1.9.3, 2.0.0, 2.1.1, ree and jruby official support(Travis build).
|
18
|
+
* Added rails 3.1, 3.2, 4.0, 4.1 support(Travis build).
|
19
|
+
* Added support for Jquery Pjax on Responder
|
20
|
+
|
21
|
+
## v1.1.1
|
22
|
+
|
23
|
+
* Fixed Service instance variable name conflict with Devise.
|
24
|
+
|
25
|
+
## v1.1.0
|
26
|
+
|
27
|
+
* Improved Controller and Service code and behavior.
|
28
|
+
|
29
|
+
## v1.0.0
|
30
|
+
|
31
|
+
* Improved Controller by letting Service choose which params to work instead of pass as arguments.
|
32
|
+
* Fixed Service instance variable name conflict with Rails one.
|
33
|
+
* Improved Accessor logic.
|
34
|
+
* Allowing full customization of Responder initialization params from Service.
|
35
|
+
* Created Responder to force redirects and flash messages.
|
36
|
+
|
37
|
+
## v0.6.1
|
38
|
+
|
39
|
+
* Fixed params working on Controller to work depending on each case.
|
40
|
+
|
41
|
+
## v0.6.0
|
42
|
+
|
43
|
+
* Added support for nested resource on Service.
|
44
|
+
|
45
|
+
## v0.5.6
|
46
|
+
|
47
|
+
* Fixed Controller `#interface_class` when name is pluralized.
|
48
|
+
|
49
|
+
## v0.5.5
|
50
|
+
|
51
|
+
* Fixed Accessor `#interface_name` and `#interface_class` bugs on namespaced interfaces.
|
52
|
+
|
53
|
+
## v0.5.4
|
54
|
+
|
55
|
+
* Fixed Accessor `#interface_name` and `#interface_class` when interface is namespaced.
|
56
|
+
|
57
|
+
## v0.5.3
|
58
|
+
|
59
|
+
* Fixed Service `#interface_name` and `#interface_class` when interface is namespaced.
|
60
|
+
|
61
|
+
## v0.5.2
|
62
|
+
|
63
|
+
* Specified Rails minimum version.
|
64
|
+
|
65
|
+
## v0.5.1
|
66
|
+
|
67
|
+
* Fixed path definition on Controller.
|
68
|
+
|
69
|
+
## v0.5.0
|
70
|
+
|
71
|
+
* Added possibility to define path to redirect on Controller.
|
72
|
+
|
73
|
+
## v0.4.0
|
74
|
+
|
75
|
+
* Added possibility to define object passed to Responder.
|
76
|
+
|
77
|
+
## v0.3.1
|
78
|
+
|
79
|
+
* Fixed `.find` method from Accessor.
|
80
|
+
|
81
|
+
## v0.3.0
|
82
|
+
|
83
|
+
* Created Accessor to encapsulate logic over interfaces.
|
84
|
+
|
85
|
+
## v0.2.0
|
86
|
+
|
87
|
+
* Improved Service to find Interface from Namespace Controller.
|
88
|
+
|
89
|
+
## v0.1.3
|
90
|
+
|
91
|
+
* Fixed Controller Initialization by executing superclass initialization.
|
92
|
+
|
93
|
+
## v0.1.2
|
94
|
+
|
95
|
+
* Fixed `#interface_name` method from Service.
|
96
|
+
|
97
|
+
## v0.1.1
|
98
|
+
|
99
|
+
* Fixed `#modify` and `#delete` methods from Service.
|
100
|
+
|
101
|
+
## v0.1.0
|
102
|
+
|
103
|
+
* Created Controller and Service to improve default Rails Controller.
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Zertico
|
2
2
|
|
3
|
-
[](http://badge.fury.io/rb/zertico) [](https://travis-ci.org/zertico/zertico) [](https://gemnasium.com/zertico/zertico) [](https://coveralls.io/r/zertico/zertico?branch=master) [](https://codeclimate.com/github/zertico/zertico) [](https://waffle.io/zertico/zertico)
|
4
4
|
|
5
5
|
Increase your Rails development speed using patterns that will make your code even more easy to read and maintain.
|
6
6
|
|
@@ -32,15 +32,22 @@ The `Zertico::Controller` define behavior of a common Rails Controller. By Exten
|
|
32
32
|
All you need to do is extend ith with you `ApplicationController` and you will get the benefit of it.
|
33
33
|
|
34
34
|
```ruby
|
35
|
-
class ApplicationController <
|
35
|
+
class ApplicationController < Zertico::Controller
|
36
36
|
respond_to :html
|
37
37
|
end
|
38
|
-
```
|
38
|
+
```
|
39
|
+
|
40
|
+
After that all your controllers will look like this:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
class CarsController < ApplicationController
|
44
|
+
end
|
45
|
+
```
|
39
46
|
|
40
47
|
### Zertico::Delegator
|
41
48
|
|
42
49
|
The `Zertico::Delegator` is a delegator with some extra tools to work with `ActiveRecord`. It will try to guess your model,
|
43
|
-
and initialize it.
|
50
|
+
and initialize it. It can be used as a Decorator.
|
44
51
|
|
45
52
|
```ruby
|
46
53
|
class UserDelegator < Zertico::Delegator
|
@@ -48,14 +55,19 @@ class UserDelegator < Zertico::Delegator
|
|
48
55
|
interface.name.downcase
|
49
56
|
end
|
50
57
|
end
|
51
|
-
```
|
52
58
|
|
53
|
-
|
59
|
+
user = UserDelegator.find(2)
|
60
|
+
puts user.interface.name
|
61
|
+
puts user.name
|
62
|
+
|
63
|
+
# 'User Name'
|
64
|
+
# 'user name'
|
65
|
+
```
|
54
66
|
|
55
67
|
### Zertico::Interactor
|
56
68
|
|
57
69
|
The `Zertico::Interactor` defines a single call on a transaction at the ruby interpreter level. It can be used to define a
|
58
|
-
database call, api call, sending of an email
|
70
|
+
database call, api call, sending of an email or calculate some data based on another interactor.
|
59
71
|
|
60
72
|
```ruby
|
61
73
|
class CreateUserInteractor < Zertico::Interactor
|
@@ -73,7 +85,7 @@ It should define its `perform` logic and `rollback` logic in case some other int
|
|
73
85
|
|
74
86
|
### Zertico::Organizer
|
75
87
|
|
76
|
-
The `Zertico::Organizer` is
|
88
|
+
The `Zertico::Organizer` is responsible for calling a pack of interactors, and in case of some failure, send a
|
77
89
|
rollback signal for all other interactors already executed.
|
78
90
|
|
79
91
|
```ruby
|
@@ -113,22 +125,32 @@ class ApplicationController < ActionController::Base
|
|
113
125
|
end
|
114
126
|
```
|
115
127
|
|
128
|
+
To force a redirect do as follows:
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
UsersController < ApplicationController
|
132
|
+
def create
|
133
|
+
@user = User.create(params[:user])
|
134
|
+
respond_with(@user, force_redirect: true) # It will redirect even on failure
|
135
|
+
end
|
136
|
+
end
|
137
|
+
```
|
138
|
+
|
116
139
|
### Zertico::Service
|
117
140
|
|
118
|
-
`Zertico::
|
119
|
-
|
120
|
-
If you define a service, you can define which class to use on that controller and even more.
|
141
|
+
When using `Zertico::Controller` your controllers will try to find a service with the same name as your controller.
|
142
|
+
If it can't find, it will initialize and `Zertico::Service` class. Creating the service, you can define which class to use on that controller.
|
121
143
|
|
122
144
|
```ruby
|
123
145
|
class AdminController < ApplicationController
|
124
146
|
end
|
125
147
|
|
126
|
-
|
127
|
-
|
148
|
+
class AdminService < Zertico::Service
|
149
|
+
use_interface User
|
150
|
+
# or
|
151
|
+
use_model User
|
128
152
|
|
129
|
-
|
130
|
-
User
|
131
|
-
end
|
153
|
+
use_as_variable_name 'epic_user'
|
132
154
|
end
|
133
155
|
```
|
134
156
|
|
@@ -156,8 +178,6 @@ The `Interactor` and `Organizer` idea was taken from [interactor](https://github
|
|
156
178
|
|
157
179
|
[@plribeiro3000](https://github.com/plribeiro3000)
|
158
180
|
|
159
|
-
[@mfbmina](https://github.com/mfbmina)
|
160
|
-
|
161
181
|
[@silviolrjunior](https://github.com/silviolrjunior)
|
162
182
|
|
163
183
|
## Contributing
|
@@ -166,4 +186,4 @@ The `Interactor` and `Organizer` idea was taken from [interactor](https://github
|
|
166
186
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
167
187
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
168
188
|
4. Push to the branch (`git push origin my-new-feature`)
|
169
|
-
5. Create new Pull Request
|
189
|
+
5. Create new Pull Request
|
data/lib/zertico.rb
CHANGED
@@ -8,6 +8,7 @@ module Zertico
|
|
8
8
|
autoload :Exceptions, 'zertico/exceptions'
|
9
9
|
autoload :Interactor, 'zertico/interactor'
|
10
10
|
autoload :Organizer, 'zertico/organizer'
|
11
|
+
autoload :PermittedParams, 'zertico/permitted_params'
|
11
12
|
autoload :Responder, 'zertico/responder'
|
12
13
|
autoload :Service, 'zertico/service'
|
13
14
|
end
|
data/lib/zertico/controller.rb
CHANGED
@@ -2,45 +2,53 @@ require 'action_controller'
|
|
2
2
|
|
3
3
|
module Zertico
|
4
4
|
class Controller < ActionController::Base
|
5
|
+
attr_reader :service
|
6
|
+
|
5
7
|
def initialize
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
@service = Zertico::Service.new
|
9
|
+
custom_service_name = "::#{self.class.name.gsub('Controller', 'Service')}"
|
10
|
+
@service = custom_service_name.constantize.new if defined?(custom_service_name)
|
11
|
+
self.class.responder = Zertico::Responder
|
12
|
+
custom_responder_name = "::#{self.class.name.gsub('Controller', 'Responder')}"
|
13
|
+
self.class.responder = custom_responder_name.constantize if defined?(custom_responder_name)
|
11
14
|
super
|
12
15
|
end
|
13
16
|
|
14
17
|
def index
|
15
|
-
|
18
|
+
instance_variable_set("@#{service.interface_name.pluralize}", service.index)
|
19
|
+
respond_with(instance_variable_get("@#{service.interface_name.pluralize}"), responder.index_options(self))
|
16
20
|
end
|
17
21
|
|
18
22
|
def new
|
19
|
-
|
23
|
+
instance_variable_set("@#{service.interface_name}", service.new)
|
24
|
+
respond_with(instance_variable_get("@#{service.interface_name}"), responder.new_options(self))
|
20
25
|
end
|
21
26
|
|
22
27
|
def show
|
23
|
-
|
28
|
+
instance_variable_set("@#{service.interface_name}", service.show(params))
|
29
|
+
respond_with(instance_variable_get("@#{service.interface_name}"), responder.show_options(self))
|
24
30
|
end
|
25
31
|
|
26
32
|
def edit
|
27
|
-
|
33
|
+
instance_variable_set("@#{service.interface_name}", service.show(params))
|
34
|
+
respond_with(instance_variable_get("@#{service.interface_name}"), responder.edit_options(self))
|
28
35
|
end
|
29
36
|
|
30
37
|
def create
|
31
|
-
|
38
|
+
permitted_params = "::#{self.class.name.chomp('Controller').concat('PermittedParams')}".constantize.new(params).create rescue params[service.interface_name.to_sym]
|
39
|
+
instance_variable_set("@#{service.interface_name}", service.create(permitted_params))
|
40
|
+
respond_with(instance_variable_get("@#{service.interface_name}"), responder.create_options(self))
|
32
41
|
end
|
33
42
|
|
34
43
|
def update
|
35
|
-
|
44
|
+
permitted_params = "::#{self.class.name.chomp('Controller').concat('PermittedParams')}".constantize.new(params).update rescue params[service.interface_name.to_sym]
|
45
|
+
instance_variable_set("@#{service.interface_name}", service.update(permitted_params))
|
46
|
+
respond_with(instance_variable_get("@#{service.interface_name}"), responder.update_options(self))
|
36
47
|
end
|
37
48
|
|
38
49
|
def destroy
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
def options
|
43
|
-
@options || {}
|
50
|
+
instance_variable_set("@#{service.interface_name}", service.destroy(params))
|
51
|
+
respond_with(instance_variable_get("@#{service.interface_name}"), responder.destroy_options(self))
|
44
52
|
end
|
45
53
|
end
|
46
54
|
end
|
data/lib/zertico/delegator.rb
CHANGED
@@ -2,6 +2,11 @@ require 'delegate'
|
|
2
2
|
|
3
3
|
module Zertico
|
4
4
|
class Delegator < SimpleDelegator
|
5
|
+
def initialize(object = nil)
|
6
|
+
object ||= interface_class.new
|
7
|
+
super(object)
|
8
|
+
end
|
9
|
+
|
5
10
|
def self.find(id)
|
6
11
|
new(interface_class.find(id))
|
7
12
|
end
|
@@ -10,6 +15,10 @@ module Zertico
|
|
10
15
|
__getobj__
|
11
16
|
end
|
12
17
|
|
18
|
+
def interface=(object)
|
19
|
+
__setobj__(object)
|
20
|
+
end
|
21
|
+
|
13
22
|
protected
|
14
23
|
|
15
24
|
def self.interface_name
|
@@ -17,11 +26,9 @@ module Zertico
|
|
17
26
|
end
|
18
27
|
|
19
28
|
def self.interface_class
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
self.name.chomp('Delegator').split('::').last.constantize
|
24
|
-
end
|
29
|
+
self.name.chomp('Delegator').constantize
|
30
|
+
rescue NameError
|
31
|
+
self.name.chomp('Delegator').split('::').last.constantize
|
25
32
|
end
|
26
33
|
|
27
34
|
def interface_name
|