simple-service 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rubocop.yml +100 -0
  4. data/.tm_properties +1 -0
  5. data/Gemfile +14 -0
  6. data/Makefile +9 -0
  7. data/README.md +68 -0
  8. data/Rakefile +6 -0
  9. data/VERSION +1 -0
  10. data/bin/bundle +105 -0
  11. data/bin/console +15 -0
  12. data/bin/rake +29 -0
  13. data/bin/rspec +29 -0
  14. data/doc/Simple.html +117 -0
  15. data/doc/Simple/Service.html +863 -0
  16. data/doc/Simple/Service/Action.html +1014 -0
  17. data/doc/Simple/Service/Action/Comment.html +451 -0
  18. data/doc/Simple/Service/Action/Comment/Extractor.html +347 -0
  19. data/doc/Simple/Service/Action/IndieHash.html +506 -0
  20. data/doc/Simple/Service/Action/MethodReflection.html +285 -0
  21. data/doc/Simple/Service/Action/Parameter.html +816 -0
  22. data/doc/Simple/Service/ArgumentError.html +128 -0
  23. data/doc/Simple/Service/ClassMethods.html +187 -0
  24. data/doc/Simple/Service/Context.html +379 -0
  25. data/doc/Simple/Service/ContextMissingError.html +124 -0
  26. data/doc/Simple/Service/ContextReadOnlyError.html +206 -0
  27. data/doc/Simple/Service/ExtraArguments.html +428 -0
  28. data/doc/Simple/Service/GemHelper.html +190 -0
  29. data/doc/Simple/Service/MissingArguments.html +426 -0
  30. data/doc/Simple/Service/NoSuchAction.html +433 -0
  31. data/doc/_index.html +286 -0
  32. data/doc/class_list.html +51 -0
  33. data/doc/css/common.css +1 -0
  34. data/doc/css/full_list.css +58 -0
  35. data/doc/css/style.css +496 -0
  36. data/doc/file.README.html +146 -0
  37. data/doc/file_list.html +56 -0
  38. data/doc/frames.html +17 -0
  39. data/doc/index.html +146 -0
  40. data/doc/js/app.js +303 -0
  41. data/doc/js/full_list.js +216 -0
  42. data/doc/js/jquery.js +4 -0
  43. data/doc/method_list.html +539 -0
  44. data/doc/top-level-namespace.html +110 -0
  45. data/lib/simple-service.rb +3 -0
  46. data/lib/simple/service.rb +173 -0
  47. data/lib/simple/service/action.rb +190 -0
  48. data/lib/simple/service/action/comment.rb +57 -0
  49. data/lib/simple/service/action/method_reflection.rb +70 -0
  50. data/lib/simple/service/action/parameter.rb +42 -0
  51. data/lib/simple/service/context.rb +94 -0
  52. data/lib/simple/service/errors.rb +54 -0
  53. data/lib/simple/service/version.rb +29 -0
  54. data/log/.gitkeep +0 -0
  55. data/scripts/release +2 -0
  56. data/scripts/release.rb +91 -0
  57. data/scripts/stats +5 -0
  58. data/scripts/watch +2 -0
  59. data/simple-service.gemspec +25 -0
  60. data/spec/simple/service/action_invoke3_spec.rb +266 -0
  61. data/spec/simple/service/action_invoke_spec.rb +166 -0
  62. data/spec/simple/service/action_spec.rb +51 -0
  63. data/spec/simple/service/context_spec.rb +69 -0
  64. data/spec/simple/service/service_spec.rb +156 -0
  65. data/spec/simple/service/version_spec.rb +7 -0
  66. data/spec/spec_helper.rb +38 -0
  67. data/spec/support/spec_services.rb +58 -0
  68. metadata +129 -0
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+
3
+ # cloc $(find lib/ -name *rb) | grep -E 'Language|Ruby' | sed 's-Language- -'
4
+ cloc --by-file --docstring-as-code --quiet --hide-rate $(find lib/ -name *rb)
5
+ printf "\n"
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ watchr lib,spec rspec $@
@@ -0,0 +1,25 @@
1
+ # lib = File.expand_path('../lib', __FILE__)
2
+ # $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "simple-service"
6
+ gem.version = File.read("VERSION")
7
+
8
+ gem.authors = [ "radiospiel" ]
9
+ gem.email = "eno@radiospiel.org"
10
+ gem.homepage = "http://github.com/radiospiel/simple-service"
11
+ gem.summary = "Pretty simple and somewhat abstract service description"
12
+
13
+ gem.description = "Pretty simple and somewhat abstract service description"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = %w(lib)
18
+
19
+ # executables are used for development purposes only
20
+ gem.executables = []
21
+
22
+ gem.required_ruby_version = '~> 2.5'
23
+
24
+ gem.add_dependency "expectation", "~> 1"
25
+ end
@@ -0,0 +1,266 @@
1
+ # rubocop:disable Style/WordArray
2
+
3
+ require "spec_helper"
4
+
5
+ describe "Simple::Service.invoke3" do
6
+ # the context to use in the around hook below. By default this is nil -
7
+ # which gives us an empty context.
8
+ let(:context) { nil }
9
+
10
+ around do |example|
11
+ ::Simple::Service.with_context(context) { example.run }
12
+ end
13
+
14
+ let(:service) { InvokeTestService }
15
+ let(:action) { nil }
16
+
17
+ # a shortcut
18
+ def invoke3!(*args, **keywords)
19
+ @actual = ::Simple::Service.invoke3(service, action, *args, **keywords)
20
+ # rescue ::StandardError => e
21
+ rescue ::Simple::Service::ArgumentError => e
22
+ @actual = e
23
+ end
24
+
25
+ attr_reader :actual
26
+
27
+ # when calling #invoke3 using positional arguments they will be matched against
28
+ # positional arguments of the invoke3d method - but they will not be matched
29
+ # against named arguments.
30
+ #
31
+ # When there are not enough positional arguments to match the number of required
32
+ # positional arguments of the method we raise an ArgumentError.
33
+ #
34
+ # When there are more positional arguments provided than the number accepted
35
+ # by the method we raise an ArgumentError.
36
+
37
+ context "calling an action w/o parameters" do
38
+ # reminder: this is the definition of no_params
39
+ #
40
+ # def no_params
41
+ # "service2 return"
42
+ # end
43
+
44
+ let(:action) { :no_params }
45
+
46
+ context "calling without args" do
47
+ it "runs the action" do
48
+ invoke3!
49
+ expect(actual).to eq("service2 return")
50
+ end
51
+ end
52
+
53
+ context "calling with extra positional args" do
54
+ it "raises ExtraArguments" do
55
+ invoke3!("foo", "bar")
56
+ expect(actual).to be_a(::Simple::Service::ExtraArguments)
57
+ expect(actual.to_s).to match(/"foo", "bar"/)
58
+ end
59
+ end
60
+
61
+ context "calling with extra named args" do
62
+ it "ignores extra args" do
63
+ invoke3!(foo: "foo", bar: "bar")
64
+ expect(actual).to eq("service2 return")
65
+ end
66
+ end
67
+
68
+ context "calling with an additional hash arg" do
69
+ xit "ignores extra args" do
70
+ args = []
71
+ args.push foo: "foo", bar: "bar"
72
+ invoke3!(*args)
73
+
74
+ expect(actual).to be_a(::Simple::Service::ExtraArguments)
75
+ end
76
+ end
77
+ end
78
+
79
+ context "calling an action w/positional parameters" do
80
+ # reminder: this is the definition of positional_params
81
+ #
82
+ # def positional_params(a, b, c = "speed-of-light", e = 2.781)
83
+ # [a, b, c, e]
84
+ # end
85
+
86
+ let(:action) { :positional_params }
87
+
88
+ context "without args" do
89
+ it "raises MissingArguments" do
90
+ invoke3!
91
+ expect(actual).to be_a(::Simple::Service::MissingArguments)
92
+ end
93
+ end
94
+
95
+ context "with the required number of args" do
96
+ it "runs" do
97
+ invoke3!("foo", "bar")
98
+ expect(actual).to eq(["foo", "bar", "speed-of-light", 2.781])
99
+ end
100
+ end
101
+
102
+ context "with the allowed number of args" do
103
+ it "runs" do
104
+ invoke3!("foo", "bar", "baz", "number4")
105
+ expect(actual).to eq(%w[foo bar baz number4])
106
+ end
107
+ end
108
+
109
+ context "with more than the allowed number of args" do
110
+ it "raises ExtraArguments" do
111
+ invoke3!("foo", "bar", "baz", "number4", "extra")
112
+ expect(actual).to be_a(::Simple::Service::ExtraArguments)
113
+ end
114
+ end
115
+
116
+ context "calling with extra named args" do
117
+ it "ignores extra args" do
118
+ invoke3!("foo", "bar", "baz", extra3: 3)
119
+ expect(actual).to eq(["foo", "bar", "baz", 2.781])
120
+ end
121
+ end
122
+
123
+ context "calling with an additional hash arg" do
124
+ xit "raises ExtraArguments" do
125
+ args = ["foo", "bar", "baz", extra3: 3]
126
+ invoke3!(*args)
127
+ expect(actual).to be_a(::Simple::Service::ExtraArguments)
128
+ end
129
+ end
130
+ end
131
+
132
+ context "calling an action w/named parameters" do
133
+ # reminder: this is the definition of named_params
134
+ #
135
+ # def named_params(a:, b:, c: "speed-of-light", e: 2.781)
136
+ # [a, b, c, e]
137
+ # end
138
+
139
+ let(:action) { :named_params }
140
+
141
+ context "without args" do
142
+ it "raises MissingArguments" do
143
+ invoke3!
144
+ expect(actual).to be_a(::Simple::Service::MissingArguments)
145
+ end
146
+ end
147
+
148
+ context "with the required number of args" do
149
+ it "runs" do
150
+ invoke3!(a: "foo", b: "bar")
151
+ expect(actual).to eq(["foo", "bar", "speed-of-light", 2.781])
152
+ end
153
+ end
154
+
155
+ context "with the allowed number of args" do
156
+ it "runs" do
157
+ invoke3!(a: "foo", b: "bar", c: "baz", e: "number4")
158
+ expect(actual).to eq(%w[foo bar baz number4])
159
+ end
160
+ end
161
+
162
+ context "with more than the allowed number of args" do
163
+ it "runs" do
164
+ invoke3!("foo", "bar", "baz", "number4", "extra")
165
+ expect(actual).to be_a(::Simple::Service::ExtraArguments)
166
+ end
167
+ end
168
+
169
+ context "with extra named args" do
170
+ it "ignores extra args" do
171
+ invoke3!(a: "foo", b: "bar", c: "baz", extra3: 3)
172
+ expect(actual).to eq(["foo", "bar", "baz", 2.781])
173
+ end
174
+ end
175
+ end
176
+
177
+ context "calling an action w/mixed and optional parameters" do
178
+ # reminder: this is the definition of named_params
179
+ #
180
+ # def mixed_optional_params(a, b = "default-b", c = "speed-of-light", e: 2.781)
181
+ # [a, b, c, e]
182
+ # end
183
+
184
+ let(:action) { :mixed_optional_params }
185
+
186
+ context "without args" do
187
+ it "raises MissingArguments" do
188
+ invoke3!
189
+ expect(actual).to be_a(::Simple::Service::MissingArguments)
190
+ end
191
+ end
192
+
193
+ context "with the required number of args" do
194
+ it "runs" do
195
+ invoke3!("foo")
196
+ expect(actual).to eq(["foo", "default-b", "speed-of-light", 2.781])
197
+ end
198
+ end
199
+
200
+ context "with the allowed number of args" do
201
+ it "runs" do
202
+ invoke3!("foo", "bar", "baz", e: "number4")
203
+ expect(actual).to eq(%w[foo bar baz number4])
204
+ end
205
+ end
206
+
207
+ context "with more than the allowed number of args" do
208
+ it "runs" do
209
+ invoke3!("foo", "bar", "baz", "extra", e: "number4")
210
+ expect(actual).to be_a(::Simple::Service::ExtraArguments)
211
+ end
212
+ end
213
+
214
+ context "with extra named args" do
215
+ it "ignores extra args" do
216
+ invoke3!("foo", "bar", "baz", e: "number4", extra3: 3)
217
+ expect(actual).to eq(["foo", "bar", "baz", "number4"])
218
+ end
219
+ end
220
+ end
221
+
222
+ context "calling an action w/mixed and variadic parameters" do
223
+ # reminder: this is the definition of variadic_params
224
+ #
225
+ # def variadic_params(a, b = "queen bee", *args, e: 2.781)
226
+ # [a, b, args, e]
227
+ # end
228
+
229
+ let(:action) { :variadic_params }
230
+
231
+ context "without args" do
232
+ it "raises MissingArguments" do
233
+ invoke3!
234
+ expect(actual).to be_a(::Simple::Service::MissingArguments)
235
+ end
236
+ end
237
+
238
+ context "with the required number of args" do
239
+ it "runs" do
240
+ invoke3!("foo")
241
+ expect(actual).to eq(["foo", "queen bee", [], 2.781])
242
+ end
243
+ end
244
+
245
+ context "with the allowed number of args" do
246
+ it "runs" do
247
+ invoke3!("foo", "bar", "baz", e: "number4")
248
+ expect(actual).to eq(["foo", "bar", ["baz"], "number4"])
249
+ end
250
+ end
251
+
252
+ context "with more than the allowed number of args" do
253
+ it "runs" do
254
+ invoke3!("foo", "bar", "baz", "extra", e: "number4")
255
+ expect(actual).to eq(["foo", "bar", ["baz", "extra"], "number4"])
256
+ end
257
+ end
258
+
259
+ context "with extra named args" do
260
+ it "ignores extra args" do
261
+ invoke3!("foo", "bar", "baz", e: "number4", extra3: 3)
262
+ expect(actual).to eq(["foo", "bar", ["baz"], "number4"])
263
+ end
264
+ end
265
+ end
266
+ end
@@ -0,0 +1,166 @@
1
+ # rubocop:disable Style/WordArray
2
+
3
+ require "spec_helper"
4
+
5
+ describe "Simple::Service.invoke" do
6
+ # the context to use in the around hook below. By default this is nil -
7
+ # which gives us an empty context.
8
+ let(:context) { nil }
9
+
10
+ around do |example|
11
+ ::Simple::Service.with_context(context) { example.run }
12
+ end
13
+
14
+ let(:service) { InvokeTestService }
15
+ let(:action) { nil }
16
+
17
+ # a shortcut
18
+ def invoke!(args = {}, flags: {})
19
+ @actual = ::Simple::Service.invoke(service, action, args: args, flags: flags)
20
+ # rescue ::StandardError => e
21
+ rescue ::Simple::Service::ArgumentError => e
22
+ @actual = e
23
+ end
24
+
25
+ attr_reader :actual
26
+
27
+ context "calling an action w/o parameters" do
28
+ # reminder: this is the definition of no_params
29
+ #
30
+ # def no_params
31
+ # "service2 return"
32
+ # end
33
+
34
+ let(:action) { :no_params }
35
+
36
+ context "calling without args" do
37
+ it "runs the action" do
38
+ invoke!
39
+ expect(actual).to eq("service2 return")
40
+ end
41
+ end
42
+
43
+ context "calling with extra named args" do
44
+ it "ignores extra args" do
45
+ invoke!("foo" => "foo", "bar" => "bar")
46
+ expect(actual).to eq("service2 return")
47
+ end
48
+ end
49
+ end
50
+
51
+ context "calling an action w/positional parameters" do
52
+ # reminder: this is the definition of positional_params
53
+ #
54
+ # def positional_params(a, b, c = "speed-of-light", e = 2.781)
55
+ # [a, b, c, e]
56
+ # end
57
+
58
+ let(:action) { :positional_params }
59
+
60
+ context "without args" do
61
+ it "raises MissingArguments" do
62
+ invoke!
63
+ expect(actual).to be_a(::Simple::Service::MissingArguments)
64
+ expect(actual.to_s).to match(/\ba, b\b/)
65
+ end
66
+ end
67
+
68
+ context "with the required number of args" do
69
+ it "runs" do
70
+ invoke!("a" => "foo", "b" => "bar")
71
+ expect(actual).to eq(["foo", "bar", "speed-of-light", 2.781])
72
+ end
73
+ end
74
+
75
+ context "with the allowed number of args" do
76
+ it "runs" do
77
+ invoke!("a" => "foo", "b" => "bar", "c" => "baz", "e" => "number4")
78
+ expect(actual).to eq(%w[foo bar baz number4])
79
+ end
80
+ end
81
+
82
+ context "calling with extra named args" do
83
+ it "ignores extra args" do
84
+ invoke!("a" => "foo", "b" => "bar", "c" => "baz", "e" => "number4", "extra3" => 3)
85
+ expect(actual).to eq(%w[foo bar baz number4])
86
+ end
87
+ end
88
+ end
89
+
90
+ context "calling an action w/named parameters" do
91
+ # reminder: this is the definition of named_params
92
+ #
93
+ # def named_params(a:, b:, "c" => "speed-of-light", e: 2.781)
94
+ # [a, b, c, e]
95
+ # end
96
+
97
+ let(:action) { :named_params }
98
+
99
+ context "without args" do
100
+ it "raises MissingArguments" do
101
+ invoke!
102
+ expect(actual).to be_a(::Simple::Service::MissingArguments)
103
+ expect(actual.to_s).to match(/\ba, b\b/)
104
+ end
105
+ end
106
+
107
+ context "with the required number of args" do
108
+ it "runs" do
109
+ invoke!("a" => "foo", "b" => "bar")
110
+ expect(actual).to eq(["foo", "bar", "speed-of-light", 2.781])
111
+ end
112
+ end
113
+
114
+ context "with the allowed number of args" do
115
+ it "runs" do
116
+ invoke!("a" => "foo", "b" => "bar", "c" => "baz", "e" => "number4")
117
+ expect(actual).to eq(%w[foo bar baz number4])
118
+ end
119
+ end
120
+
121
+ context "with extra named args" do
122
+ it "ignores extra args" do
123
+ invoke!("a" => "foo", "b" => "bar", "c" => "baz", "extra3" => 3)
124
+ expect(actual).to eq(["foo", "bar", "baz", 2.781])
125
+ end
126
+ end
127
+ end
128
+
129
+ context "calling an action w/mixed and optional parameters" do
130
+ # reminder: this is the definition of named_params
131
+ #
132
+ # def mixed_optional_params(a, b = "default-b", c = "speed-of-light", e: 2.781)
133
+ # [a, b, c, e]
134
+ # end
135
+
136
+ let(:action) { :mixed_optional_params }
137
+
138
+ context "without args" do
139
+ it "raises MissingArguments" do
140
+ invoke!
141
+ expect(actual).to be_a(::Simple::Service::MissingArguments)
142
+ end
143
+ end
144
+
145
+ context "with the required number of args" do
146
+ it "runs" do
147
+ invoke!("a" => "foo")
148
+ expect(actual).to eq(["foo", "default-b", "speed-of-light", 2.781])
149
+ end
150
+ end
151
+
152
+ context "with the allowed number of args" do
153
+ it "runs" do
154
+ invoke!("a" => "foo", "b" => "bar", "c" => "baz", "e" => "number4")
155
+ expect(actual).to eq(%w[foo bar baz number4])
156
+ end
157
+ end
158
+
159
+ context "with extra named args" do
160
+ it "ignores extra args" do
161
+ invoke!("a" => "foo", "b" => "bar", "c" => "baz", "e" => "number4", "extra3" => 3)
162
+ expect(actual).to eq(["foo", "bar", "baz", "number4"])
163
+ end
164
+ end
165
+ end
166
+ end