simple-service 0.1.3 → 0.2.0
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 -2
- data/.rubocop.yml +10 -2
- data/Gemfile +3 -1
- data/Makefile +7 -11
- data/README.md +67 -2
- data/TODO.txt +3 -0
- data/VERSION +1 -1
- data/doc/Simple/Service/Action/Comment/Extractor.html +347 -0
- data/doc/Simple/Service/Action/Comment.html +451 -0
- data/doc/Simple/Service/Action/MethodReflection.html +285 -0
- data/doc/Simple/Service/Action/Parameter.html +816 -0
- data/doc/Simple/Service/Action.html +923 -0
- data/doc/Simple/Service/ArgumentError.html +128 -0
- data/doc/Simple/Service/ClassMethods.html +187 -0
- data/doc/Simple/Service/Context.html +379 -0
- data/doc/Simple/Service/ContextMissingError.html +124 -0
- data/doc/Simple/Service/ContextReadOnlyError.html +206 -0
- data/doc/Simple/Service/ExtraArguments.html +428 -0
- data/doc/Simple/Service/GemHelper.html +190 -0
- data/doc/Simple/Service/MissingArguments.html +426 -0
- data/doc/Simple/Service/NoSuchAction.html +433 -0
- data/doc/Simple/Service.html +865 -0
- data/doc/Simple.html +117 -0
- data/doc/_index.html +274 -0
- data/doc/class_list.html +51 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +496 -0
- data/doc/file.README.html +146 -0
- data/doc/file.TODO.html +70 -0
- data/doc/file_list.html +61 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +146 -0
- data/doc/js/app.js +303 -0
- data/doc/js/full_list.js +216 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +483 -0
- data/doc/top-level-namespace.html +110 -0
- data/lib/simple/service/action/comment.rb +2 -2
- data/lib/simple/service/action/method_reflection.rb +1 -1
- data/lib/simple/service/action/parameter.rb +1 -1
- data/lib/simple/service/action.rb +34 -46
- data/lib/simple/service/errors.rb +4 -3
- data/lib/simple/service/version.rb +2 -2
- data/lib/simple/service.rb +109 -34
- data/lib/simple/workflow/context.rb +105 -0
- data/lib/simple/workflow/current_context.rb +33 -0
- data/lib/simple/workflow/reloader.rb +84 -0
- data/lib/simple/workflow/rspec_helper.rb +15 -0
- data/lib/simple/workflow.rb +96 -0
- data/lib/simple-workflow.rb +3 -0
- data/scripts/test +2 -0
- data/simple-service.gemspec +1 -0
- data/spec/simple/service/action_invoke3_spec.rb +258 -0
- data/spec/simple/service/action_invoke_spec.rb +49 -87
- data/spec/simple/service/service_spec.rb +40 -32
- data/spec/simple/workflow/context_spec.rb +90 -0
- data/spec/simple/workflow/current_context_spec.rb +41 -0
- data/spec/simple/workflow/reloader_spec/example1.rb +10 -0
- data/spec/simple/workflow/reloader_spec/example2.rb +7 -0
- data/spec/simple/workflow/reloader_spec.rb +48 -0
- data/spec/spec_helper.rb +2 -1
- data/spec/support/spec_services.rb +8 -2
- metadata +74 -9
- data/lib/simple/service/action/indie_hash.rb +0 -37
- data/lib/simple/service/context.rb +0 -94
- data/spec/simple/service/action_invoke2_spec.rb +0 -166
- data/spec/simple/service/context_spec.rb +0 -69
@@ -1,166 +0,0 @@
|
|
1
|
-
# rubocop:disable Style/WordArray
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe "Simple::Service.invoke2" 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 invoke2!(**hsh)
|
19
|
-
@actual = ::Simple::Service.invoke2(service, action, args: hsh)
|
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
|
-
invoke2!
|
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
|
-
invoke2!(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
|
-
invoke2!
|
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
|
-
invoke2!(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
|
-
invoke2!(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
|
-
invoke2!(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
|
-
invoke2!
|
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
|
-
invoke2!(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
|
-
invoke2!(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
|
-
invoke2!(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
|
-
invoke2!
|
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
|
-
invoke2!(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
|
-
invoke2!(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
|
-
invoke2!(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
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Simple::Service do
|
4
|
-
describe ".with_context" do
|
5
|
-
it "merges the current context for the duration of the block" do
|
6
|
-
block_called = false
|
7
|
-
|
8
|
-
Simple::Service.with_context(a: "a") do
|
9
|
-
expect(Simple::Service.context.a).to eq("a")
|
10
|
-
|
11
|
-
# overwrite value
|
12
|
-
Simple::Service.with_context(a: "b") do
|
13
|
-
expect(Simple::Service.context.a).to eq("b")
|
14
|
-
block_called = true
|
15
|
-
end
|
16
|
-
|
17
|
-
# overwrite value w/nil
|
18
|
-
Simple::Service.with_context(a: nil) do
|
19
|
-
expect(Simple::Service.context.a).to be_nil
|
20
|
-
Simple::Service.context.a = "c"
|
21
|
-
expect(Simple::Service.context.a).to eq("c")
|
22
|
-
end
|
23
|
-
expect(Simple::Service.context.a).to eq("a")
|
24
|
-
end
|
25
|
-
|
26
|
-
expect(block_called).to eq(true)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe Simple::Service::Context do
|
32
|
-
let(:context) { Simple::Service::Context.new }
|
33
|
-
|
34
|
-
before do
|
35
|
-
context.one = 1
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "invalid identifier" do
|
39
|
-
it "raises an error" do
|
40
|
-
expect { context.one! }.to raise_error(NoMethodError)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "context reading" do
|
45
|
-
it "returns a value if set" do
|
46
|
-
expect(context.one).to eq(1)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "returns nil if not set" do
|
50
|
-
expect(context.two).to be_nil
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "context writing" do
|
55
|
-
it "sets a value if it does not exist yet" do
|
56
|
-
context.two = 2
|
57
|
-
expect(context.two).to eq(2)
|
58
|
-
end
|
59
|
-
|
60
|
-
it "raises a ReadOnly error if the value exists and is not equal" do
|
61
|
-
expect { context.one = 2 }.to raise_error(::Simple::Service::ContextReadOnlyError)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "sets the value if it exists and is equal" do
|
65
|
-
context.one = 1
|
66
|
-
expect(context.one).to eq(1)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|