simple-service 0.1.5 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +10 -2
  3. data/Gemfile +3 -1
  4. data/Makefile +5 -2
  5. data/TODO.txt +3 -0
  6. data/VERSION +1 -1
  7. data/doc/Simple/Service/Action/Comment/Extractor.html +1 -1
  8. data/doc/Simple/Service/Action/Comment.html +1 -1
  9. data/doc/Simple/Service/Action/MethodReflection.html +1 -1
  10. data/doc/Simple/Service/Action/Parameter.html +2 -2
  11. data/doc/Simple/Service/Action.html +59 -150
  12. data/doc/Simple/Service/ArgumentError.html +1 -1
  13. data/doc/Simple/Service/ClassMethods.html +5 -5
  14. data/doc/Simple/Service/Context.html +5 -5
  15. data/doc/Simple/Service/ContextMissingError.html +1 -1
  16. data/doc/Simple/Service/ContextReadOnlyError.html +1 -1
  17. data/doc/Simple/Service/ExtraArguments.html +1 -1
  18. data/doc/Simple/Service/GemHelper.html +1 -1
  19. data/doc/Simple/Service/MissingArguments.html +1 -1
  20. data/doc/Simple/Service/NoSuchAction.html +1 -1
  21. data/doc/Simple/Service.html +89 -87
  22. data/doc/Simple.html +1 -1
  23. data/doc/_index.html +7 -19
  24. data/doc/class_list.html +1 -1
  25. data/doc/file.README.html +3 -3
  26. data/doc/file.TODO.html +70 -0
  27. data/doc/file_list.html +5 -0
  28. data/doc/index.html +3 -3
  29. data/doc/method_list.html +59 -115
  30. data/doc/top-level-namespace.html +1 -1
  31. data/lib/simple/service/action/comment.rb +1 -1
  32. data/lib/simple/service/action.rb +10 -3
  33. data/lib/simple/service/errors.rb +4 -3
  34. data/lib/simple/service.rb +33 -28
  35. data/lib/simple/workflow/context.rb +105 -0
  36. data/lib/simple/workflow/current_context.rb +33 -0
  37. data/lib/simple/workflow/reloader.rb +84 -0
  38. data/lib/simple/workflow/rspec_helper.rb +15 -0
  39. data/lib/simple/workflow.rb +96 -0
  40. data/lib/simple-workflow.rb +3 -0
  41. data/scripts/test +2 -0
  42. data/simple-service.gemspec +1 -0
  43. data/spec/simple/service/action_invoke3_spec.rb +0 -8
  44. data/spec/simple/service/action_invoke_spec.rb +82 -20
  45. data/spec/simple/service/service_spec.rb +13 -56
  46. data/spec/simple/workflow/context_spec.rb +90 -0
  47. data/spec/simple/workflow/current_context_spec.rb +41 -0
  48. data/spec/simple/workflow/reloader_spec/example1.rb +10 -0
  49. data/spec/simple/workflow/reloader_spec/example2.rb +7 -0
  50. data/spec/simple/workflow/reloader_spec.rb +48 -0
  51. data/spec/spec_helper.rb +2 -1
  52. data/spec/support/spec_services.rb +1 -3
  53. metadata +42 -7
  54. data/doc/Simple/Service/Action/IndieHash.html +0 -506
  55. data/lib/simple/service/context.rb +0 -94
  56. data/spec/simple/service/context_spec.rb +0 -69
@@ -1,15 +1,11 @@
1
1
  require "spec_helper"
2
2
 
3
+ # rubocop:disable Style/WordArray
4
+
3
5
  describe "Simple::Service" do
4
6
  context "when running against a NoService module" do
5
7
  let(:service) { NoServiceModule }
6
8
 
7
- describe ".service?" do
8
- it "returns false on a NoService module" do
9
- expect(Simple::Service.service?(service)).to eq(false)
10
- end
11
- end
12
-
13
9
  describe ".actions" do
14
10
  it "raises an argument error" do
15
11
  expect { Simple::Service.actions(service) }.to raise_error(ArgumentError)
@@ -24,9 +20,7 @@ describe "Simple::Service" do
24
20
 
25
21
  describe ".invoke3" do
26
22
  it "raises an argument error" do
27
- ::Simple::Service.with_context do
28
- expect { Simple::Service.invoke3(service, :service1, {}, {}, context: nil) }.to raise_error(::ArgumentError)
29
- end
23
+ expect { Simple::Service.invoke3(service, :service1, {}, {}, context: nil) }.to raise_error(::ArgumentError)
30
24
  end
31
25
  end
32
26
  end
@@ -34,12 +28,6 @@ describe "Simple::Service" do
34
28
  # running against a proper service module
35
29
  let(:service) { SpecService }
36
30
 
37
- describe ".service?" do
38
- it "returns true" do
39
- expect(Simple::Service.service?(service)).to eq(true)
40
- end
41
- end
42
-
43
31
  describe ".actions" do
44
32
  it "returns a Hash of actions on a Service module" do
45
33
  actions = Simple::Service.actions(service)
@@ -76,31 +64,16 @@ describe "Simple::Service" do
76
64
  end
77
65
  end
78
66
 
79
- describe '.invoke3' do
67
+ describe ".invoke3" do
80
68
  def invoke3
81
69
  Simple::Service.invoke3(service, :service1, "my_a", "my_b", d: "my_d")
82
70
  end
83
71
 
84
- context "when context is not set" do
85
- it "raises a ContextMissingError" do
86
- action = Simple::Service.actions(service)[:service1]
87
- expect(action).not_to receive(:invoke)
88
-
89
- expect do
90
- invoke3
91
- end.to raise_error(::Simple::Service::ContextMissingError)
92
- end
93
- end
94
-
95
- context "when context is set" do
96
- it "calls Action#invoke with the right arguments" do
97
- action = Simple::Service.actions(service)[:service1]
98
- expect(action).to receive(:invoke).with(args: ["my_a", "my_b"], flags: { "d" => "my_d" })
72
+ it "calls Action#invoke with the right arguments" do
73
+ action = Simple::Service.actions(service)[:service1]
74
+ expect(action).to receive(:invoke).with(args: ["my_a", "my_b"], flags: { "d" => "my_d" })
99
75
 
100
- ::Simple::Service.with_context do
101
- invoke3
102
- end
103
- end
76
+ invoke3
104
77
  end
105
78
  end
106
79
 
@@ -110,26 +83,11 @@ describe "Simple::Service" do
110
83
  Simple::Service.invoke(service, :service1, args: ["my_a", "my_b"], flags: { "d" => "my_d" })
111
84
  end
112
85
 
113
- context "when context is not set" do
114
- it "raises a ContextMissingError" do
115
- action = Simple::Service.actions(service)[:service1]
116
- expect(action).not_to receive(:invoke)
117
-
118
- expect do
119
- invoke
120
- end.to raise_error(::Simple::Service::ContextMissingError)
121
- end
122
- end
123
-
124
- context "when context is set" do
125
- it "calls Action#invoke with the right arguments" do
126
- action = Simple::Service.actions(service)[:service1]
127
- expect(action).to receive(:invoke).with(args: ["my_a", "my_b"], flags: { "d" => "my_d" }).and_call_original
86
+ it "calls Action#invoke with the right arguments" do
87
+ action = Simple::Service.actions(service)[:service1]
88
+ expect(action).to receive(:invoke).with(args: ["my_a", "my_b"], flags: { "d" => "my_d" }).and_call_original
128
89
 
129
- ::Simple::Service.with_context do
130
- invoke
131
- end
132
- end
90
+ invoke
133
91
  end
134
92
  end
135
93
  end
@@ -145,12 +103,11 @@ describe "Simple::Service" do
145
103
 
146
104
  it "calls Action#invoke with the right arguments" do
147
105
  expected = ["bar-value", "baz-value"]
148
- ::Simple::Service.with_context do
106
+
149
107
  expect(invoke3("bar-value", baz: "baz-value")).to eq(expected)
150
108
  expect(invoke3(bar: "bar-value", baz: "baz-value")).to eq(expected)
151
109
  expect(invoke(args: ["bar-value"], flags: { "baz" => "baz-value" })).to eq(expected)
152
110
  expect(invoke(args: { "bar" => "bar-value", "baz" => "baz-value" })).to eq(expected)
153
111
  end
154
- end
155
112
  end
156
113
  end
@@ -0,0 +1,90 @@
1
+ require "spec_helper"
2
+
3
+ describe Simple::Workflow::Context do
4
+ RSpec.shared_examples "context requesting" do
5
+ it "inherits from Simple::Immutable" do
6
+ expect(context).to be_a(Simple::Immutable)
7
+ end
8
+
9
+ describe "checking for identifier" do
10
+ it "raises an ArgumentError if the key is invalid" do
11
+ expect { context.oneTwoThree? }.to raise_error(ArgumentError)
12
+ end
13
+
14
+ it "returns nil if the key is not set" do
15
+ expect(context.two?).to be_nil
16
+ end
17
+
18
+ it "returns the value if the key is set" do
19
+ expect(context.one?).to eq 1
20
+ end
21
+ end
22
+
23
+ describe "fetching identifier" do
24
+ it "raises an ArgumentError if the identifier is invalid" do
25
+ expect { context.one! }.to raise_error(ArgumentError)
26
+ expect { context.oneTwoThree }.to raise_error(ArgumentError)
27
+ end
28
+
29
+ it "raises a NoMethodError if the key is not set" do
30
+ expect { context.two }.to raise_error(NameError)
31
+ end
32
+
33
+ it "returns the value if the key is set" do
34
+ expect(context.one).to eq 1
35
+ end
36
+ end
37
+
38
+ describe "#merge" do
39
+ context "with symbolized keys" do
40
+ it "sets a value if it does not exist yet" do
41
+ expect(context.two?).to eq(nil)
42
+ new_context = Simple::Workflow::Context.new({two: 2}, context)
43
+ expect(new_context.two).to eq(2)
44
+
45
+ # doesn't change the source context
46
+ expect(context.two?).to eq(nil)
47
+ end
48
+
49
+ it "sets a value if it does exist" do
50
+ new_context = Simple::Workflow::Context.new({one: 2}, context)
51
+ expect(new_context.one).to eq(2)
52
+
53
+ # doesn't change the source context
54
+ expect(context.one).to eq(1)
55
+ end
56
+ end
57
+
58
+ context "with stringified keys" do
59
+ it "sets a value if it does not exist yet" do
60
+ expect(context.two?).to eq(nil)
61
+ new_context = Simple::Workflow::Context.new({"two" => 2}, context)
62
+ expect(new_context.two).to eq(2)
63
+
64
+ # doesn't change the source context
65
+ expect(context.two?).to eq(nil)
66
+ end
67
+
68
+ it "sets a value if it does exist" do
69
+ new_context = Simple::Workflow::Context.new({"one" => 2}, context)
70
+ expect(new_context.one).to eq(2)
71
+
72
+ # doesn't change the source context
73
+ expect(context.one).to eq(1)
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ context "with a symbolized context" do
80
+ let(:context) { Simple::Workflow::Context.new(one: 1) }
81
+
82
+ it_behaves_like "context requesting"
83
+ end
84
+
85
+ context "with a stringified context" do
86
+ let(:context) { Simple::Workflow::Context.new("one" => 1) }
87
+
88
+ it_behaves_like "context requesting"
89
+ end
90
+ end
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+
3
+ describe Simple::Workflow::CurrentContext 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::Workflow.with_context(a: "a", foo: "bar") do
9
+ expect(Simple::Workflow.current_context.a).to eq("a")
10
+ expect(Simple::Workflow.current_context.foo).to eq("bar")
11
+
12
+ # layering
13
+ Simple::Workflow.with_context() do
14
+ expect(Simple::Workflow.current_context.foo).to eq("bar")
15
+
16
+ expect(Simple::Workflow.current_context.unknown?).to be_nil
17
+ expect {
18
+ Simple::Workflow.current_context.unknown
19
+ }.to raise_error(NameError)
20
+ end
21
+
22
+ # overwrite value
23
+ Simple::Workflow.with_context(a: "b") do
24
+ expect(Simple::Workflow.current_context.a).to eq("b")
25
+ block_called = true
26
+ end
27
+
28
+ # overwrite value w/nil
29
+ Simple::Workflow.with_context(a: nil) do
30
+ expect(Simple::Workflow.current_context.a).to be_nil
31
+ Simple::Workflow.with_context(a: "c") do
32
+ expect(Simple::Workflow.current_context.a).to eq("c")
33
+ end
34
+ end
35
+ expect(Simple::Workflow.current_context.a).to eq("a")
36
+ end
37
+
38
+ expect(block_called).to eq(true)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,10 @@
1
+ module ReloaderSpecExample1
2
+ def foo; end
3
+ end
4
+
5
+ module ReloaderSpecExample2
6
+ end
7
+
8
+ module ReloaderSpecExample3
9
+ def foo; end
10
+ end
@@ -0,0 +1,7 @@
1
+ module ReloaderSpecExample1
2
+ def self.bar; end
3
+ end
4
+
5
+ module ReloaderSpecExample2
6
+ def self.bar; end
7
+ end
@@ -0,0 +1,48 @@
1
+ require "spec_helper"
2
+
3
+ require_relative "reloader_spec/example1"
4
+ require_relative "reloader_spec/example2"
5
+
6
+ describe "Simple::Service::Reloader" do
7
+ describe ".locate" do
8
+ def locate(mod)
9
+ Simple::Workflow::Reloader.locate(mod)
10
+ end
11
+
12
+ it "Returns all source files of a module" do
13
+ root = Dir.getwd
14
+
15
+ expected = [
16
+ "#{root}/lib/simple/workflow/reloader.rb"
17
+ ]
18
+ expect(locate(Simple::Workflow::Reloader)).to contain_exactly(*expected)
19
+
20
+ expected = [
21
+ "#{__dir__}/reloader_spec/example1.rb",
22
+ "#{__dir__}/reloader_spec/example2.rb"
23
+ ]
24
+ expect(locate(ReloaderSpecExample1)).to contain_exactly(*expected)
25
+
26
+ expected = [
27
+ "#{__dir__}/reloader_spec/example2.rb"
28
+ ]
29
+ expect(locate(ReloaderSpecExample2)).to contain_exactly(*expected)
30
+
31
+ expected = [
32
+ "#{__dir__}/reloader_spec/example1.rb"
33
+ ]
34
+ expect(locate(ReloaderSpecExample3)).to contain_exactly(*expected)
35
+ end
36
+ end
37
+
38
+ describe ".reload" do
39
+ def reload(mod)
40
+ Simple::Workflow::Reloader.reload(mod)
41
+ end
42
+
43
+ it "Reloads a module" do
44
+ # [TODO] this doesn't really check reloading...
45
+ reload Simple::Workflow::Reloader
46
+ end
47
+ end
48
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  ENV["RACK_ENV"] = "test"
2
2
  ENV["RAILS_ENV"] = "test"
3
3
 
4
- require "byebug"
4
+ require "pry-byebug"
5
5
  require "rspec"
6
6
 
7
7
  require "simplecov"
@@ -18,6 +18,7 @@ SimpleCov.start do
18
18
  end
19
19
 
20
20
  require "simple/service"
21
+ require "simple/workflow"
21
22
 
22
23
  Dir.glob("./spec/support/**/*.rb").sort.each { |path| load path }
23
24
 
@@ -1,5 +1,3 @@
1
- # rubocop:disable Naming/UncommunicativeMethodParamName
2
-
3
1
  module NoServiceModule
4
2
  end
5
3
 
@@ -53,6 +51,6 @@ module SpecTestService
53
51
  include Simple::Service
54
52
 
55
53
  def foo(bar, baz:)
56
- [ bar, baz ]
54
+ [bar, baz]
57
55
  end
58
56
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - radiospiel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-04 00:00:00.000000000 Z
11
+ date: 2022-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: expectation
@@ -24,6 +24,26 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: simple-immutable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '1.1'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '1.1'
27
47
  description: Pretty simple and somewhat abstract service description
28
48
  email: eno@radiospiel.org
29
49
  executables: []
@@ -37,6 +57,7 @@ files:
37
57
  - Makefile
38
58
  - README.md
39
59
  - Rakefile
60
+ - TODO.txt
40
61
  - VERSION
41
62
  - bin/bundle
42
63
  - bin/console
@@ -47,7 +68,6 @@ files:
47
68
  - doc/Simple/Service/Action.html
48
69
  - doc/Simple/Service/Action/Comment.html
49
70
  - doc/Simple/Service/Action/Comment/Extractor.html
50
- - doc/Simple/Service/Action/IndieHash.html
51
71
  - doc/Simple/Service/Action/MethodReflection.html
52
72
  - doc/Simple/Service/Action/Parameter.html
53
73
  - doc/Simple/Service/ArgumentError.html
@@ -65,6 +85,7 @@ files:
65
85
  - doc/css/full_list.css
66
86
  - doc/css/style.css
67
87
  - doc/file.README.html
88
+ - doc/file.TODO.html
68
89
  - doc/file_list.html
69
90
  - doc/frames.html
70
91
  - doc/index.html
@@ -74,26 +95,36 @@ files:
74
95
  - doc/method_list.html
75
96
  - doc/top-level-namespace.html
76
97
  - lib/simple-service.rb
98
+ - lib/simple-workflow.rb
77
99
  - lib/simple/service.rb
78
100
  - lib/simple/service/action.rb
79
101
  - lib/simple/service/action/comment.rb
80
102
  - lib/simple/service/action/method_reflection.rb
81
103
  - lib/simple/service/action/parameter.rb
82
- - lib/simple/service/context.rb
83
104
  - lib/simple/service/errors.rb
84
105
  - lib/simple/service/version.rb
106
+ - lib/simple/workflow.rb
107
+ - lib/simple/workflow/context.rb
108
+ - lib/simple/workflow/current_context.rb
109
+ - lib/simple/workflow/reloader.rb
110
+ - lib/simple/workflow/rspec_helper.rb
85
111
  - log/.gitkeep
86
112
  - scripts/release
87
113
  - scripts/release.rb
88
114
  - scripts/stats
115
+ - scripts/test
89
116
  - scripts/watch
90
117
  - simple-service.gemspec
91
118
  - spec/simple/service/action_invoke3_spec.rb
92
119
  - spec/simple/service/action_invoke_spec.rb
93
120
  - spec/simple/service/action_spec.rb
94
- - spec/simple/service/context_spec.rb
95
121
  - spec/simple/service/service_spec.rb
96
122
  - spec/simple/service/version_spec.rb
123
+ - spec/simple/workflow/context_spec.rb
124
+ - spec/simple/workflow/current_context_spec.rb
125
+ - spec/simple/workflow/reloader_spec.rb
126
+ - spec/simple/workflow/reloader_spec/example1.rb
127
+ - spec/simple/workflow/reloader_spec/example2.rb
97
128
  - spec/spec_helper.rb
98
129
  - spec/support/spec_services.rb
99
130
  homepage: http://github.com/radiospiel/simple-service
@@ -114,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
145
  - !ruby/object:Gem::Version
115
146
  version: '0'
116
147
  requirements: []
117
- rubygems_version: 3.0.4
148
+ rubygems_version: 3.1.4
118
149
  signing_key:
119
150
  specification_version: 4
120
151
  summary: Pretty simple and somewhat abstract service description
@@ -122,8 +153,12 @@ test_files:
122
153
  - spec/simple/service/action_invoke3_spec.rb
123
154
  - spec/simple/service/action_invoke_spec.rb
124
155
  - spec/simple/service/action_spec.rb
125
- - spec/simple/service/context_spec.rb
126
156
  - spec/simple/service/service_spec.rb
127
157
  - spec/simple/service/version_spec.rb
158
+ - spec/simple/workflow/context_spec.rb
159
+ - spec/simple/workflow/current_context_spec.rb
160
+ - spec/simple/workflow/reloader_spec.rb
161
+ - spec/simple/workflow/reloader_spec/example1.rb
162
+ - spec/simple/workflow/reloader_spec/example2.rb
128
163
  - spec/spec_helper.rb
129
164
  - spec/support/spec_services.rb