simple-service 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/.rubocop.yml +10 -2
  4. data/Gemfile +3 -1
  5. data/Makefile +7 -11
  6. data/README.md +67 -2
  7. data/TODO.txt +3 -0
  8. data/VERSION +1 -1
  9. data/doc/Simple/Service/Action/Comment/Extractor.html +347 -0
  10. data/doc/Simple/Service/Action/Comment.html +451 -0
  11. data/doc/Simple/Service/Action/MethodReflection.html +285 -0
  12. data/doc/Simple/Service/Action/Parameter.html +816 -0
  13. data/doc/Simple/Service/Action.html +923 -0
  14. data/doc/Simple/Service/ArgumentError.html +128 -0
  15. data/doc/Simple/Service/ClassMethods.html +187 -0
  16. data/doc/Simple/Service/Context.html +379 -0
  17. data/doc/Simple/Service/ContextMissingError.html +124 -0
  18. data/doc/Simple/Service/ContextReadOnlyError.html +206 -0
  19. data/doc/Simple/Service/ExtraArguments.html +428 -0
  20. data/doc/Simple/Service/GemHelper.html +190 -0
  21. data/doc/Simple/Service/MissingArguments.html +426 -0
  22. data/doc/Simple/Service/NoSuchAction.html +433 -0
  23. data/doc/Simple/Service.html +865 -0
  24. data/doc/Simple.html +117 -0
  25. data/doc/_index.html +274 -0
  26. data/doc/class_list.html +51 -0
  27. data/doc/css/common.css +1 -0
  28. data/doc/css/full_list.css +58 -0
  29. data/doc/css/style.css +496 -0
  30. data/doc/file.README.html +146 -0
  31. data/doc/file.TODO.html +70 -0
  32. data/doc/file_list.html +61 -0
  33. data/doc/frames.html +17 -0
  34. data/doc/index.html +146 -0
  35. data/doc/js/app.js +303 -0
  36. data/doc/js/full_list.js +216 -0
  37. data/doc/js/jquery.js +4 -0
  38. data/doc/method_list.html +483 -0
  39. data/doc/top-level-namespace.html +110 -0
  40. data/lib/simple/service/action/comment.rb +2 -2
  41. data/lib/simple/service/action/method_reflection.rb +1 -1
  42. data/lib/simple/service/action/parameter.rb +1 -1
  43. data/lib/simple/service/action.rb +34 -46
  44. data/lib/simple/service/errors.rb +4 -3
  45. data/lib/simple/service/version.rb +2 -2
  46. data/lib/simple/service.rb +109 -34
  47. data/lib/simple/workflow/context.rb +105 -0
  48. data/lib/simple/workflow/current_context.rb +33 -0
  49. data/lib/simple/workflow/reloader.rb +84 -0
  50. data/lib/simple/workflow/rspec_helper.rb +15 -0
  51. data/lib/simple/workflow.rb +96 -0
  52. data/lib/simple-workflow.rb +3 -0
  53. data/scripts/test +2 -0
  54. data/simple-service.gemspec +1 -0
  55. data/spec/simple/service/action_invoke3_spec.rb +258 -0
  56. data/spec/simple/service/action_invoke_spec.rb +49 -87
  57. data/spec/simple/service/service_spec.rb +40 -32
  58. data/spec/simple/workflow/context_spec.rb +90 -0
  59. data/spec/simple/workflow/current_context_spec.rb +41 -0
  60. data/spec/simple/workflow/reloader_spec/example1.rb +10 -0
  61. data/spec/simple/workflow/reloader_spec/example2.rb +7 -0
  62. data/spec/simple/workflow/reloader_spec.rb +48 -0
  63. data/spec/spec_helper.rb +2 -1
  64. data/spec/support/spec_services.rb +8 -2
  65. metadata +74 -9
  66. data/lib/simple/service/action/indie_hash.rb +0 -37
  67. data/lib/simple/service/context.rb +0 -94
  68. data/spec/simple/service/action_invoke2_spec.rb +0 -166
  69. 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