service_objects 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.metrics +1 -0
  4. data/.travis.yml +9 -1
  5. data/.yardopts +1 -1
  6. data/Gemfile +1 -1
  7. data/Guardfile +29 -8
  8. data/LICENSE +1 -1
  9. data/README.md +179 -342
  10. data/Rakefile +3 -3
  11. data/config/metrics/churn.yml +1 -1
  12. data/config/metrics/flay.yml +1 -1
  13. data/config/metrics/metric_fu.yml +1 -0
  14. data/config/metrics/rubocop.yml +4 -4
  15. data/config/metrics/simplecov.yml +1 -1
  16. data/lib/service_objects.rb +6 -9
  17. data/lib/service_objects/base.rb +190 -17
  18. data/lib/service_objects/listener.rb +21 -75
  19. data/lib/service_objects/message.rb +15 -96
  20. data/lib/service_objects/version.rb +1 -1
  21. data/service_objects.gemspec +11 -9
  22. data/spec/lib/base_spec.rb +247 -0
  23. data/spec/lib/listener_spec.rb +96 -0
  24. data/spec/lib/message_spec.rb +48 -0
  25. data/spec/spec_helper.rb +8 -6
  26. metadata +56 -93
  27. data/bin/service +0 -17
  28. data/config/metrics/pippi.yml +0 -3
  29. data/lib/service_objects/cli.rb +0 -117
  30. data/lib/service_objects/cli/locale.erb +0 -20
  31. data/lib/service_objects/cli/service.erb +0 -125
  32. data/lib/service_objects/cli/spec.erb +0 -87
  33. data/lib/service_objects/helpers.rb +0 -17
  34. data/lib/service_objects/helpers/dependable.rb +0 -63
  35. data/lib/service_objects/helpers/exceptions.rb +0 -64
  36. data/lib/service_objects/helpers/messages.rb +0 -95
  37. data/lib/service_objects/helpers/parameterized.rb +0 -85
  38. data/lib/service_objects/helpers/parameters.rb +0 -71
  39. data/lib/service_objects/helpers/validations.rb +0 -54
  40. data/lib/service_objects/invalid.rb +0 -55
  41. data/lib/service_objects/null.rb +0 -26
  42. data/lib/service_objects/parsers.rb +0 -13
  43. data/lib/service_objects/parsers/dependency.rb +0 -69
  44. data/lib/service_objects/parsers/notification.rb +0 -85
  45. data/lib/service_objects/rspec.rb +0 -75
  46. data/lib/service_objects/utils/normal_hash.rb +0 -34
  47. data/spec/tests/base_spec.rb +0 -43
  48. data/spec/tests/bin/service_spec.rb +0 -18
  49. data/spec/tests/cli_spec.rb +0 -179
  50. data/spec/tests/helpers/dependable_spec.rb +0 -77
  51. data/spec/tests/helpers/exceptions_spec.rb +0 -112
  52. data/spec/tests/helpers/messages_spec.rb +0 -64
  53. data/spec/tests/helpers/parameterized_spec.rb +0 -136
  54. data/spec/tests/helpers/parameters_spec.rb +0 -71
  55. data/spec/tests/helpers/validations_spec.rb +0 -60
  56. data/spec/tests/invalid_spec.rb +0 -69
  57. data/spec/tests/listener_spec.rb +0 -73
  58. data/spec/tests/message_spec.rb +0 -191
  59. data/spec/tests/null_spec.rb +0 -17
  60. data/spec/tests/parsers/dependency_spec.rb +0 -29
  61. data/spec/tests/parsers/notification_spec.rb +0 -84
  62. data/spec/tests/rspec_spec.rb +0 -86
  63. data/spec/tests/utils/normal_hash_spec.rb +0 -16
metadata CHANGED
@@ -1,104 +1,116 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: service_objects
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kozin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-19 00:00:00.000000000 Z
11
+ date: 2015-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activemodel
14
+ name: attestor
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
15
20
  requirement: !ruby/object:Gem::Requirement
16
21
  requirements:
17
22
  - - "~>"
18
23
  - !ruby/object:Gem::Version
19
- version: '4.1'
20
- type: :runtime
24
+ version: '2.2'
21
25
  prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: attr_coerced
22
29
  version_requirements: !ruby/object:Gem::Requirement
23
30
  requirements:
24
31
  - - "~>"
25
32
  - !ruby/object:Gem::Version
26
- version: '4.1'
27
- - !ruby/object:Gem::Dependency
28
- name: extlib
33
+ version: '0.0'
29
34
  requirement: !ruby/object:Gem::Requirement
30
35
  requirements:
31
36
  - - "~>"
32
37
  - !ruby/object:Gem::Version
33
- version: '0.9'
34
- type: :runtime
38
+ version: '0.0'
35
39
  prerelease: false
40
+ type: :runtime
41
+ - !ruby/object:Gem::Dependency
42
+ name: chronicles
36
43
  version_requirements: !ruby/object:Gem::Requirement
37
44
  requirements:
38
45
  - - "~>"
39
46
  - !ruby/object:Gem::Version
40
- version: '0.9'
41
- - !ruby/object:Gem::Dependency
42
- name: naught
47
+ version: '0.0'
43
48
  requirement: !ruby/object:Gem::Requirement
44
49
  requirements:
45
50
  - - "~>"
46
51
  - !ruby/object:Gem::Version
47
- version: '1.0'
48
- type: :runtime
52
+ version: '0.0'
49
53
  prerelease: false
54
+ type: :runtime
55
+ - !ruby/object:Gem::Dependency
56
+ name: virtus
50
57
  version_requirements: !ruby/object:Gem::Requirement
51
58
  requirements:
52
59
  - - "~>"
53
60
  - !ruby/object:Gem::Version
54
61
  version: '1.0'
55
- - !ruby/object:Gem::Dependency
56
- name: wisper
57
62
  requirement: !ruby/object:Gem::Requirement
58
63
  requirements:
59
64
  - - "~>"
60
65
  - !ruby/object:Gem::Version
61
- version: '1.6'
62
- type: :runtime
66
+ version: '1.0'
63
67
  prerelease: false
68
+ type: :runtime
69
+ - !ruby/object:Gem::Dependency
70
+ name: wisper
64
71
  version_requirements: !ruby/object:Gem::Requirement
65
72
  requirements:
66
73
  - - "~>"
67
74
  - !ruby/object:Gem::Version
68
75
  version: '1.6'
69
- - !ruby/object:Gem::Dependency
70
- name: hexx-cli
71
76
  requirement: !ruby/object:Gem::Requirement
72
77
  requirements:
73
78
  - - "~>"
74
79
  - !ruby/object:Gem::Version
75
- version: '0.0'
76
- type: :runtime
80
+ version: '1.6'
77
81
  prerelease: false
82
+ type: :runtime
83
+ - !ruby/object:Gem::Dependency
84
+ name: hexx-cli
78
85
  version_requirements: !ruby/object:Gem::Requirement
79
86
  requirements:
80
87
  - - "~>"
81
88
  - !ruby/object:Gem::Version
82
89
  version: '0.0'
83
- - !ruby/object:Gem::Dependency
84
- name: hexx-rspec
85
90
  requirement: !ruby/object:Gem::Requirement
86
91
  requirements:
87
92
  - - "~>"
88
93
  - !ruby/object:Gem::Version
89
- version: '0.3'
90
- type: :development
94
+ version: '0.0'
91
95
  prerelease: false
96
+ type: :development
97
+ - !ruby/object:Gem::Dependency
98
+ name: hexx-rspec
92
99
  version_requirements: !ruby/object:Gem::Requirement
93
100
  requirements:
94
101
  - - "~>"
95
102
  - !ruby/object:Gem::Version
96
- version: '0.3'
97
- description: Base class for objects, that implements both the Interactor and Observer
98
- design patterns.
103
+ version: '0.4'
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '0.4'
109
+ prerelease: false
110
+ type: :development
111
+ description: Base class for objects, that implements both the Interactor and Observer design patterns.
99
112
  email: andrew.kozin@gmail.com
100
- executables:
101
- - service
113
+ executables: []
102
114
  extensions: []
103
115
  extra_rdoc_files:
104
116
  - README.md
@@ -116,13 +128,11 @@ files:
116
128
  - LICENSE
117
129
  - README.md
118
130
  - Rakefile
119
- - bin/service
120
131
  - config/metrics/STYLEGUIDE
121
132
  - config/metrics/cane.yml
122
133
  - config/metrics/churn.yml
123
134
  - config/metrics/flay.yml
124
135
  - config/metrics/metric_fu.yml
125
- - config/metrics/pippi.yml
126
136
  - config/metrics/reek.yml
127
137
  - config/metrics/roodi.yml
128
138
  - config/metrics/rubocop.yml
@@ -131,51 +141,19 @@ files:
131
141
  - config/metrics/yardstick.yml
132
142
  - lib/service_objects.rb
133
143
  - lib/service_objects/base.rb
134
- - lib/service_objects/cli.rb
135
- - lib/service_objects/cli/locale.erb
136
- - lib/service_objects/cli/service.erb
137
- - lib/service_objects/cli/spec.erb
138
- - lib/service_objects/helpers.rb
139
- - lib/service_objects/helpers/dependable.rb
140
- - lib/service_objects/helpers/exceptions.rb
141
- - lib/service_objects/helpers/messages.rb
142
- - lib/service_objects/helpers/parameterized.rb
143
- - lib/service_objects/helpers/parameters.rb
144
- - lib/service_objects/helpers/validations.rb
145
- - lib/service_objects/invalid.rb
146
144
  - lib/service_objects/listener.rb
147
145
  - lib/service_objects/message.rb
148
- - lib/service_objects/null.rb
149
- - lib/service_objects/parsers.rb
150
- - lib/service_objects/parsers/dependency.rb
151
- - lib/service_objects/parsers/notification.rb
152
- - lib/service_objects/rspec.rb
153
- - lib/service_objects/utils/normal_hash.rb
154
146
  - lib/service_objects/version.rb
155
147
  - service_objects.gemspec
148
+ - spec/lib/base_spec.rb
149
+ - spec/lib/listener_spec.rb
150
+ - spec/lib/message_spec.rb
156
151
  - spec/spec_helper.rb
157
- - spec/tests/base_spec.rb
158
- - spec/tests/bin/service_spec.rb
159
- - spec/tests/cli_spec.rb
160
- - spec/tests/helpers/dependable_spec.rb
161
- - spec/tests/helpers/exceptions_spec.rb
162
- - spec/tests/helpers/messages_spec.rb
163
- - spec/tests/helpers/parameterized_spec.rb
164
- - spec/tests/helpers/parameters_spec.rb
165
- - spec/tests/helpers/validations_spec.rb
166
- - spec/tests/invalid_spec.rb
167
- - spec/tests/listener_spec.rb
168
- - spec/tests/message_spec.rb
169
- - spec/tests/null_spec.rb
170
- - spec/tests/parsers/dependency_spec.rb
171
- - spec/tests/parsers/notification_spec.rb
172
- - spec/tests/rspec_spec.rb
173
- - spec/tests/utils/normal_hash_spec.rb
174
152
  homepage: https://github.com/nepalez/service_objects
175
153
  licenses:
176
154
  - MIT
177
155
  metadata: {}
178
- post_install_message:
156
+ post_install_message:
179
157
  rdoc_options: []
180
158
  require_paths:
181
159
  - lib
@@ -183,35 +161,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
161
  requirements:
184
162
  - - "~>"
185
163
  - !ruby/object:Gem::Version
186
- version: '2.1'
164
+ version: '2.0'
187
165
  required_rubygems_version: !ruby/object:Gem::Requirement
188
166
  requirements:
189
167
  - - ">="
190
168
  - !ruby/object:Gem::Version
191
169
  version: '0'
192
170
  requirements: []
193
- rubyforge_project:
194
- rubygems_version: 2.4.6
195
- signing_key:
171
+ rubyforge_project:
172
+ rubygems_version: 2.4.5
173
+ signing_key:
196
174
  specification_version: 4
197
175
  summary: Service objects (interactors).
198
176
  test_files:
199
177
  - spec/spec_helper.rb
200
- - spec/tests/listener_spec.rb
201
- - spec/tests/message_spec.rb
202
- - spec/tests/cli_spec.rb
203
- - spec/tests/null_spec.rb
204
- - spec/tests/base_spec.rb
205
- - spec/tests/parsers/dependency_spec.rb
206
- - spec/tests/parsers/notification_spec.rb
207
- - spec/tests/invalid_spec.rb
208
- - spec/tests/helpers/parameterized_spec.rb
209
- - spec/tests/helpers/parameters_spec.rb
210
- - spec/tests/helpers/messages_spec.rb
211
- - spec/tests/helpers/validations_spec.rb
212
- - spec/tests/helpers/exceptions_spec.rb
213
- - spec/tests/helpers/dependable_spec.rb
214
- - spec/tests/utils/normal_hash_spec.rb
215
- - spec/tests/bin/service_spec.rb
216
- - spec/tests/rspec_spec.rb
217
- has_rdoc:
178
+ - spec/lib/listener_spec.rb
179
+ - spec/lib/message_spec.rb
180
+ - spec/lib/base_spec.rb
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require "service_objects/cli"
3
-
4
- # Scaffolders runner from the command line
5
- class CLI < Thor
6
-
7
- register(
8
- ServiceObjects::CLI,
9
- "new",
10
- "new NAME[ -d dependency{Default}][ -p option][ -n notification]" \
11
- "[ -l en[ ru]][ -f folder]",
12
- "Scaffolds a service object with a specification and translations."
13
- )
14
-
15
- end # class CLI
16
-
17
- CLI.start
@@ -1,3 +0,0 @@
1
- ---
2
- checkset: basic
3
- output: "tmp/pippi/output.log"
@@ -1,117 +0,0 @@
1
- # encoding: utf-8
2
- require "hexx-cli"
3
-
4
- module ServiceObjects
5
-
6
- require_relative "parsers"
7
-
8
- # Scaffolds a service object with a specification and translations
9
- class CLI < Hexx::CLI::Base
10
-
11
- # @private
12
- def self.source_root
13
- ::File.expand_path "../cli", __FILE__
14
- end
15
-
16
- desc "Scaffolds a service object with a specification and translations."
17
- namespace :new
18
-
19
- argument(
20
- :name,
21
- banner: "NAME",
22
- desc: "The name of the service",
23
- type: :string
24
- )
25
-
26
- class_option(
27
- :dependencies,
28
- aliases: %w(-d),
29
- banner: "name{value}",
30
- default: %w(),
31
- desc: "The list of dependencies for the service object",
32
- type: :array
33
- )
34
-
35
- class_option(
36
- :params,
37
- aliases: %w(-p),
38
- default: %w(),
39
- desc: "The list of service object's parameters",
40
- type: :array
41
- )
42
-
43
- class_option(
44
- :notifications,
45
- aliases: %w(-n),
46
- default: %w(),
47
- desc: "The list of notifications, published by a service",
48
- type: :array
49
- )
50
-
51
- class_option(
52
- :locales,
53
- aliases: %w(-l),
54
- default: %w(en ru),
55
- desc: "The list of locales (languages) for message translations",
56
- type: :array
57
- )
58
-
59
- class_option(
60
- :folder,
61
- aliases: %w(-f),
62
- default: %w(services),
63
- desc: "The folder namespace for the service",
64
- type: :array
65
- )
66
-
67
- # @private
68
- def add_specification
69
- template "spec.erb", "spec/tests/#{ service.path }_spec.rb"
70
- end
71
-
72
- # @private
73
- def add_service
74
- template "service.erb", "app/#{ service.path }.rb"
75
- end
76
-
77
- # @private
78
- def add_locales
79
- locales.each do |lang|
80
- @locale = lang
81
- template "locale.erb", "config/locales/#{ service.path }/#{ lang }.yml"
82
- end
83
- end
84
-
85
- private
86
-
87
- def service
88
- @service ||= Hexx::CLI::Name.new [options[:folder], name].join("/")
89
- end
90
-
91
- def project
92
- @project ||= Hexx::CLI::Name.new ::File.basename(destination_root)
93
- end
94
-
95
- def params
96
- @params ||= options[:params].map(&:downcase)
97
- end
98
-
99
- def locales
100
- @locales ||= options[:locales].map(&:downcase)
101
- end
102
-
103
- def notifications
104
- @notifications ||=
105
- options[:notifications]
106
- .map(&Parsers::Notification.method(:new))
107
- end
108
-
109
- def dependencies
110
- @dependencies ||=
111
- options[:dependencies]
112
- .map(&Parsers::Dependency.method(:new))
113
- end
114
-
115
- end # class CLI
116
-
117
- end # module ServiceObjects
@@ -1,20 +0,0 @@
1
- # encoding: utf-8
2
- # Translations for errors and other messages, generated by services of type:
3
- # <%= service.type %>
4
- ---
5
- # <%= @locale %>:
6
- # activemodel:
7
- # errors:
8
- # models:
9
- # <%= project.path %>/<%= service.path %>:
10
- # attributes:
11
- # base:
12
- <% params.sort.each do |item| -%>
13
- # <%= item %>:
14
- <% end -%>
15
- # messages:
16
- # models:
17
- # <%= project.path %>/<%= service.path %>:
18
- <% notifications.select(&:publish_messages?).each do |item| -%>
19
- # <%= item.name %>: @todo
20
- <% end -%>
@@ -1,125 +0,0 @@
1
- # encoding: utf-8
2
- <% tabs = 0 -%>
3
- <% project.namespaces.each do |item| -%>
4
-
5
- <%= " " * tabs %>module <%= item %>
6
- <% tabs += 1 -%>
7
- <% end -%>
8
-
9
- <%= " " * tabs %>module <%= project.const %>
10
- <% tabs += 1 -%>
11
- <% service.namespaces.each do |item| -%>
12
-
13
- <%= " " * tabs %>module <%= item %>
14
- <% tabs += 1 -%>
15
- <% end -%>
16
-
17
- <%= " " * tabs %># @todo: describe what the service does
18
- <% if dependencies.any? -%>
19
- <%= " " * tabs %>#
20
- <%= " " * tabs %># Uses other services:
21
- <% dependencies.each do |item| -%>
22
- <%= " " * tabs %># * <%= item.name %> (<%= item.type %>)
23
- <%= " " * tabs %># @todo: describe what is it for
24
- <% end -%>
25
- <% end -%>
26
- <%= " " * tabs %>#
27
- <%= " " * tabs %># @example
28
- <%= " " * tabs %># service = <%= service.type %>.new(
29
- <% params.each do |item| -%>
30
- <%= " " * tabs %># <%= item %>: @todo,
31
- <% end -%>
32
- <%= " " * tabs %># )
33
- <%= " " * tabs %># service.subscribe listener
34
- <%= " " * tabs %># service.run
35
- <%= " " * tabs %>#
36
- <%= " " * tabs %># @param [Hash] params
37
- <% params.each do |item| -%>
38
- <%= " " * tabs %># @option params [@todo] :<%= item %>
39
- <%= " " * tabs %># @todo: describe the option
40
- <% end -%>
41
- <%= " " * tabs %>#
42
- <% notifications.each do |item| -%>
43
- <%= " " * tabs %># @publish <%= item.name %>(<%= item.args.join(", ") %>)
44
- <%= " " * tabs %># @todo: describe the condition
45
- <% end -%>
46
- <%= " " * tabs %>class <%= service.const %> < ServiceObjects::Base
47
- <% dependencies.each do |item| -%>
48
-
49
- <%= " " * tabs %> # @!attribute <%= item.name %>
50
- <%= " " * tabs %> # @todo: describe the dependency
51
- <%= " " * tabs %> # @return [Class]
52
- <%= " " * tabs %> depends_on <%= item.name %>, default: <%= item.type %>
53
- <% end -%>
54
- <% if params.any? -%>
55
-
56
- <%= " " * tabs %> # Params definition
57
- <%= " " * tabs %> allows_params <%= params.map { |item| ":" << item }.join(", ") %>
58
- <% end -%>
59
- <% if notifications.any? -%>
60
-
61
- <%= " " * tabs %> # Internal exceptions
62
- <% notifications.reject(&:error?).to_a[1..-1].to_a.each do |item| -%>
63
- <%= " " * tabs %> <%= item.exception %> = Class.new Invalid
64
- <% end -%>
65
- <% end -%>
66
-
67
- <%= " " * tabs %> # Runs the service and publishes its results
68
- <%= " " * tabs %> #
69
- <%= " " * tabs %> # @example (see <%= project.type %>::<%= service.type %>)
70
- <%= " " * tabs %> #
71
- <%= " " * tabs %> # @publish (see <%= project.type %>::<%= service.type %>)
72
- <%= " " * tabs %> #
73
- <%= " " * tabs %> # @return [undefined]
74
- <%= " " * tabs %> def run
75
- <%= " " * tabs %> run!
76
- <% notifications.reject(&:error?).to_a[1..-1].to_a.each do |item| -%>
77
- <%= " " * tabs %> rescue <%= item.exception %>
78
- <%= " " * tabs %> publish :<%= item.name %>, <%= item.args.join(", ") %>
79
- <% end -%>
80
- <%= " " * tabs %> rescue Invalid => err
81
- <%= " " * tabs %> publish :error, err.messages
82
- <%= " " * tabs %> else
83
- <% if (item = notifications.reject(&:error?).first) -%>
84
- <%= " " * tabs %> publish :<%= item.name %>, <%= item.args.join(", ") %>
85
- <% else -%>
86
- <%= " " * tabs %> # publish :something
87
- <% end -%>
88
- <%= " " * tabs %> end
89
-
90
- <%= " " * tabs %> private
91
-
92
- <%= " " * tabs %> def run!
93
- <%= " " * tabs %> end
94
- <% notifications.flat_map(&:non_messages).uniq.each do |item| -%>
95
-
96
- <%= " " * tabs %> def <%= item %>
97
- <%= " " * tabs %> end
98
- <% end -%>
99
- <% dependencies.each do |item| -%>
100
-
101
- <%= " " * tabs %> # The listener of notifications from {#<%= item.name %>}
102
- <%= " " * tabs %> class <%= item.listener %> < ServiceObjects::Listener
103
-
104
- <%= " " * tabs %> # Callback to be called when no other callback received
105
- <%= " " * tabs %> # @return [undefined]
106
- <%= " " * tabs %> def otherwise
107
- <%= " " * tabs %> end
108
-
109
- <%= " " * tabs %> end # class <%= item.listener %>
110
- <% end -%>
111
-
112
- <%= " " * tabs %>end # class <%= service.const %>
113
- <% service.namespaces.reverse.each do |item| -%>
114
-
115
- <% tabs -= 1 -%>
116
- <%= " " * tabs -%>end # module <%= item %>
117
- <% end -%>
118
-
119
- <% tabs -= 1 -%>
120
- <%= " " * tabs -%>end # module <%= project.const %>
121
- <% project.namespaces.reverse.each do |item| -%>
122
-
123
- <% tabs -= 1 -%>
124
- <%= " " * tabs -%>end # module <%= item %>
125
- <% end -%>