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.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.hound.yml +17 -0
  4. data/.travis.yml +36 -23
  5. data/CHANGELOG.md +103 -0
  6. data/README.md +39 -19
  7. data/gemfiles/Gemfile.rails3-ruby1.8.7 +7 -0
  8. data/gemfiles/Gemfile.rails3-ruby1.9.2+ +6 -0
  9. data/gemfiles/Gemfile.rails4-ruby1.9.2+ +5 -0
  10. data/lib/zertico.rb +1 -0
  11. data/lib/zertico/controller.rb +24 -16
  12. data/lib/zertico/delegator.rb +12 -5
  13. data/lib/zertico/exceptions.rb +1 -0
  14. data/lib/zertico/exceptions/missing_strong_parameters.rb +9 -0
  15. data/lib/zertico/interactor.rb +15 -2
  16. data/lib/zertico/organizer.rb +7 -5
  17. data/lib/zertico/permitted_params.rb +21 -0
  18. data/lib/zertico/responder.rb +16 -31
  19. data/lib/zertico/responder/force_redirect.rb +34 -0
  20. data/lib/zertico/responder/pjax.rb +13 -0
  21. data/lib/zertico/service.rb +5 -62
  22. data/lib/zertico/service/class_methods.rb +29 -0
  23. data/lib/zertico/service/instance_methods.rb +60 -0
  24. data/lib/zertico/version.rb +1 -1
  25. data/spec/fake_app/app/controllers/admin/user_controller.rb +6 -0
  26. data/spec/fake_app/app/controllers/application_controller.rb +7 -0
  27. data/spec/fake_app/app/controllers/person/gifts_controller.rb +6 -0
  28. data/spec/fake_app/app/controllers/person/profile_controller.rb +6 -0
  29. data/spec/fake_app/app/controllers/user_controller.rb +2 -0
  30. data/spec/fake_app/app/controllers/users_controller.rb +7 -0
  31. data/spec/fake_app/{delegators → app/delegators}/admin/user_delegator.rb +0 -0
  32. data/spec/fake_app/{delegators → app/delegators}/profile/profile_delegator.rb +0 -0
  33. data/spec/fake_app/{delegators → app/delegators}/user_delegator.rb +0 -0
  34. data/spec/fake_app/{interactors → app/interactors}/create_invoice_interactor.rb +0 -0
  35. data/spec/fake_app/{interactors → app/interactors}/create_product_interactor.rb +0 -0
  36. data/spec/fake_app/{interactors → app/interactors}/create_user_interactor.rb +0 -0
  37. data/spec/fake_app/{interactors → app/interactors}/send_welcome_email_interactor.rb +0 -0
  38. data/spec/fake_app/{interfaces → app/interfaces}/invoice.rb +0 -0
  39. data/spec/fake_app/{interfaces → app/interfaces}/person/profile.rb +0 -0
  40. data/spec/fake_app/{interfaces → app/interfaces}/product.rb +0 -0
  41. data/spec/fake_app/app/interfaces/user.rb +32 -0
  42. data/spec/fake_app/{organizers → app/organizers}/buy_product_organizer.rb +0 -0
  43. data/spec/fake_app/{organizers → app/organizers}/register_organizer.rb +0 -0
  44. data/spec/fake_app/app/permitted_params/users_permitted_params.rb +9 -0
  45. data/spec/fake_app/app/responders/users_responder.rb +5 -0
  46. data/spec/fake_app/app/services/admin/user_service.rb +6 -0
  47. data/spec/fake_app/app/services/person/gifts_service.rb +4 -0
  48. data/spec/fake_app/app/services/person/profile_service.rb +4 -0
  49. data/spec/fake_app/app/services/user_service.rb +5 -0
  50. data/spec/fake_app/app/services/users_service.rb +3 -0
  51. data/spec/fake_app/app/views/layouts/application.html.erb +1 -0
  52. data/spec/fake_app/app/views/users/edit.html.erb +0 -0
  53. data/spec/fake_app/app/views/users/index.html.erb +0 -0
  54. data/spec/fake_app/app/views/users/new.html.erb +0 -0
  55. data/spec/fake_app/app/views/users/show.html.erb +0 -0
  56. data/spec/fake_app/config/application.rb +10 -0
  57. data/spec/fake_app/config/routes.rb +3 -0
  58. data/spec/fake_app/config/secrets.yml +4 -0
  59. data/spec/spec_helper.rb +17 -3
  60. data/spec/zertico/controller_integration_spec.rb +92 -0
  61. data/spec/zertico/controller_spec.rb +14 -151
  62. data/spec/zertico/delegator_spec.rb +60 -11
  63. data/spec/zertico/interactor_spec.rb +41 -1
  64. data/spec/zertico/organizer_spec.rb +21 -4
  65. data/spec/zertico/permitted_params_spec.rb +25 -0
  66. data/spec/zertico/responder_spec.rb +234 -0
  67. data/spec/zertico/service/class_methods_spec.rb +36 -0
  68. data/spec/zertico/service/instance_methods_spec.rb +218 -0
  69. data/zertico.gemspec +10 -2
  70. metadata +139 -55
  71. data/gemfiles/Gemfile.rails3.1 +0 -5
  72. data/gemfiles/Gemfile.rails3.2 +0 -5
  73. data/gemfiles/Gemfile.rails4.0 +0 -5
  74. data/gemfiles/Gemfile.rails4.1 +0 -5
  75. data/spec/fake_app/controllers/admin/user_controller.rb +0 -4
  76. data/spec/fake_app/controllers/profile/profile_controller.rb +0 -4
  77. data/spec/fake_app/controllers/user_controller.rb +0 -2
  78. data/spec/fake_app/controllers/users_controller.rb +0 -2
  79. data/spec/fake_app/interfaces/user.rb +0 -9
  80. data/spec/fake_app/services/admin/user_service.rb +0 -8
  81. data/spec/fake_app/services/person/profile_service.rb +0 -5
  82. data/spec/fake_app/services/user_service.rb +0 -6
  83. data/spec/zertico/service_spec.rb +0 -162
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1295fd48c55975eb821b72ef4aecbf18718a1ba8
4
- data.tar.gz: 42084f48151b1c217ba9f06457f88b891957559c
3
+ metadata.gz: 612a9f684881747d1a85ca57c61e15ee06e2b9ca
4
+ data.tar.gz: 09f94e32870ed318a59852e560ede7816026c4ec
5
5
  SHA512:
6
- metadata.gz: ee89cd13512c57ee180a2c77740066dfdcb310642b7d77af31e54a8d5e353fe6b5fee1cf6f033815f7f500bcb8f8d018c249387b8b4112efdde121639da185e3
7
- data.tar.gz: 9a9dc13bb60edc54a4d84e982e7e7c15c1b8ba626cf9c6c1880f2500529b7e77fa3c75641e0a6f97ca5112354953b235e2ed07ae05f05fdae2566906f7be2fea
6
+ metadata.gz: 9edf88ad4dbe5c8a8c48ec01e2b02b776c62a35345e60444ea8adba06b7278be112ef2c8b8b629641263ccca771000c61a2d710288c2fe5feb9981aac2117655
7
+ data.tar.gz: a07da191a75726a209a6cc15bb0eecb51caa7dca8a16ccff860eeb4805f1f229f6b0681abb4c043a987b10c58b950e21218fb10ab0371fd758596fe0ba953404
data/.gitignore CHANGED
@@ -15,4 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
- .coveralls.yml
18
+ .coveralls.yml
19
+ gemfiles/*.lock
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
- exclude:
2
+ include:
16
3
  - rvm: 1.8.7
17
- gemfile: gemfiles/Gemfile.rails4.0
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.rails4.0
22
- - rvm: 1.8.7
23
- gemfile: gemfiles/Gemfile.rails4.1
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.rails4.1
26
- - rvm: 1.9.2
27
- gemfile: gemfiles/Gemfile.rails4.1
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
- [![Gem Version](https://badge.fury.io/rb/zertico.png)](http://badge.fury.io/rb/zertico) [![Build Status](https://travis-ci.org/zertico/zertico.png)](https://travis-ci.org/zertico/zertico) [![Dependency Status](https://gemnasium.com/zertico/zertico.png)](https://gemnasium.com/zertico/zertico) [![Coverage Status](https://coveralls.io/repos/zertico/zertico/badge.png?branch=master)](https://coveralls.io/r/zertico/zertico) [![Code Climate](https://codeclimate.com/github/zertico/zertico.png)](https://codeclimate.com/github/zertico/zertico)
3
+ [![Gem Version](https://badge.fury.io/rb/zertico.svg)](http://badge.fury.io/rb/zertico) [![Build Status](https://travis-ci.org/zertico/zertico.svg?branch=master)](https://travis-ci.org/zertico/zertico) [![Dependency Status](https://gemnasium.com/zertico/zertico.svg)](https://gemnasium.com/zertico/zertico) [![Coverage Status](https://img.shields.io/coveralls/zertico/zertico.svg?branch=master)](https://coveralls.io/r/zertico/zertico?branch=master) [![Code Climate](https://codeclimate.com/github/zertico/zertico.png)](https://codeclimate.com/github/zertico/zertico) [![Stories in Ready](https://badge.waffle.io/zertico/zertico.png?label=ready&title=Ready)](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 < ZerticoController
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
- In the above example, it will automatically load a `User` model.
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, calculate some data based on another interactor.
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 the responsible for calling a pack of interactors, and in case of some failure, send a
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::Service` gives more flexibility to the `Zertico::Controller`. When using `Zertico::Controller` your controllers
119
- will try to find a module with the same name as your controller. If it can't find, it will include `Zertico::Service`.
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
- module UsersService
127
- include Zertico::Service
148
+ class AdminService < Zertico::Service
149
+ use_interface User
150
+ # or
151
+ use_model User
128
152
 
129
- def interface_class
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
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gem 'rails', '~> 3.1.0'
4
+ gem 'rest-client', '~> 1.6.8'
5
+ gem 'strong_parameters'
6
+
7
+ gemspec :path => '../'
@@ -0,0 +1,6 @@
1
+ source :rubygems
2
+
3
+ gem 'rails', '~> 3.1.0'
4
+ gem 'strong_parameters'
5
+
6
+ gemspec :path => '../'
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem 'rails', '~> 4.0.0'
4
+
5
+ gemspec :path => '../'
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
@@ -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
- begin
7
- extend "::#{self.class.name.chomp('Controller').concat('Service')}".constantize
8
- rescue NameError
9
- extend Zertico::Service
10
- end
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
- respond_with(all, options)
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
- respond_with(build, options)
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
- respond_with(find, options)
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
- respond_with(find, options)
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
- respond_with(generate, options)
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
- respond_with(modify, options)
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
- respond_with(delete, options)
40
- end
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
@@ -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
- begin
21
- self.name.chomp('Delegator').constantize
22
- rescue NameError
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