simple-service 0.1.4

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.
Files changed (69) 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 +143 -0
  47. data/lib/simple/service/action.rb +203 -0
  48. data/lib/simple/service/action/comment.rb +57 -0
  49. data/lib/simple/service/action/indie_hash.rb +37 -0
  50. data/lib/simple/service/action/method_reflection.rb +70 -0
  51. data/lib/simple/service/action/parameter.rb +42 -0
  52. data/lib/simple/service/context.rb +94 -0
  53. data/lib/simple/service/errors.rb +54 -0
  54. data/lib/simple/service/version.rb +29 -0
  55. data/log/.gitkeep +0 -0
  56. data/scripts/release +2 -0
  57. data/scripts/release.rb +91 -0
  58. data/scripts/stats +5 -0
  59. data/scripts/watch +2 -0
  60. data/simple-service.gemspec +25 -0
  61. data/spec/simple/service/action_invoke2_spec.rb +166 -0
  62. data/spec/simple/service/action_invoke_spec.rb +266 -0
  63. data/spec/simple/service/action_spec.rb +51 -0
  64. data/spec/simple/service/context_spec.rb +69 -0
  65. data/spec/simple/service/service_spec.rb +105 -0
  66. data/spec/simple/service/version_spec.rb +7 -0
  67. data/spec/spec_helper.rb +38 -0
  68. data/spec/support/spec_services.rb +50 -0
  69. metadata +130 -0
@@ -0,0 +1,51 @@
1
+ require "spec_helper"
2
+
3
+ describe Simple::Service::Action do
4
+ let(:service) { SpecService }
5
+
6
+ let(:service1) { ::Simple::Service.action(service, :service1) }
7
+ let(:service2) { ::Simple::Service.action(service, :service2) }
8
+ let(:service3) { ::Simple::Service.action(service, :service3) }
9
+
10
+ describe "attributes" do
11
+ describe "#service" do
12
+ it "returns the service module" do
13
+ expect(service1.service).to eq(service)
14
+ end
15
+ end
16
+
17
+ describe "#name" do
18
+ it "returns the action name" do
19
+ expect(service1.name).to eq(:service1)
20
+ end
21
+ end
22
+
23
+ describe "full_name" do
24
+ it "returns the full_name" do
25
+ expect(service1.full_name).to eq("SpecService#service1")
26
+ end
27
+ end
28
+
29
+ describe "to_s" do
30
+ it "returns the full_name" do
31
+ expect(service1.to_s).to eq("SpecService#service1")
32
+ end
33
+ end
34
+
35
+ describe "#short_description" do
36
+ it "returns the short_description as per source code" do
37
+ expect(service1.short_description).to eq("This is service1")
38
+ expect(service2.short_description).to eq("This is service2 (no full description)")
39
+ expect(service3.short_description).to eq(nil)
40
+ end
41
+ end
42
+
43
+ describe "#full_description" do
44
+ it "returns the full_description as per source code" do
45
+ expect(service1.full_description).to eq("Service 1 has a full description")
46
+ expect(service2.full_description).to eq(nil)
47
+ expect(service3.full_description).to eq(nil)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,69 @@
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
@@ -0,0 +1,105 @@
1
+ require "spec_helper"
2
+
3
+ describe "Simple::Service" do
4
+ context "when running against a NoService module" do
5
+ let(:service) { NoServiceModule }
6
+
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
+ describe ".actions" do
14
+ it "raises an argument error" do
15
+ expect { Simple::Service.actions(service) }.to raise_error(ArgumentError)
16
+ end
17
+ end
18
+
19
+ describe ".action" do
20
+ it "raises an argument error" do
21
+ expect { Simple::Service.action(service, :service1) }.to raise_error(ArgumentError)
22
+ end
23
+ end
24
+
25
+ describe ".invoke" do
26
+ it "raises an argument error" do
27
+ ::Simple::Service.with_context do
28
+ expect { Simple::Service.invoke(service, :service1, {}, {}, context: nil) }.to raise_error(::ArgumentError)
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ # running against a proper service module
35
+ let(:service) { SpecService }
36
+
37
+ describe ".service?" do
38
+ it "returns true" do
39
+ expect(Simple::Service.service?(service)).to eq(true)
40
+ end
41
+ end
42
+
43
+ describe ".actions" do
44
+ it "returns a Hash of actions on a Service module" do
45
+ actions = Simple::Service.actions(service)
46
+ expect(actions).to be_a(Hash)
47
+ expect(actions.keys).to contain_exactly(:service1, :service2, :service3)
48
+ end
49
+ end
50
+
51
+ describe ".action" do
52
+ context "with an existing name" do
53
+ it "returns a Action object" do
54
+ action = Simple::Service.action(service, :service1)
55
+ expect(action.service).to eq(service)
56
+ expect(action.name).to eq(:service1)
57
+ end
58
+ end
59
+
60
+ describe "Simple::Service::NoSuchAction" do
61
+ it "does not inherit from Simple::Service::ArgumentError" do
62
+ expect(Simple::Service::NoSuchAction < Simple::Service::ArgumentError).to be_falsey
63
+ end
64
+
65
+ it "inherits from ArgumentError" do
66
+ expect(Simple::Service::NoSuchAction < ::ArgumentError).to eq true
67
+ end
68
+ end
69
+
70
+ context "with an unknown name" do
71
+ it "raises a NoSuchAction error" do
72
+ expect do
73
+ Simple::Service.action(service, :no_such_service)
74
+ end.to raise_error(Simple::Service::NoSuchAction, /No such action :no_such_service/)
75
+ end
76
+ end
77
+ end
78
+
79
+ describe ".invoke" do
80
+ let(:positionals) { { a: "my_a", b: "my_b" } }
81
+ let(:named) { { d: "my_d" } }
82
+
83
+ context "when context is not set" do
84
+ it "raises a ContextMissingError" do
85
+ action = Simple::Service.actions(service)[:service1]
86
+ expect(action).not_to receive(:invoke)
87
+
88
+ expect do
89
+ Simple::Service.invoke(service, :service1, *positionals, named_args: named)
90
+ end.to raise_error(::Simple::Service::ContextMissingError)
91
+ end
92
+ end
93
+
94
+ context "when context is not set" do
95
+ it "properly delegates call to action object" do
96
+ action = Simple::Service.actions(service)[:service1]
97
+ expect(action).to receive(:invoke).with(*positionals, named_args: named)
98
+
99
+ ::Simple::Service.with_context do
100
+ Simple::Service.invoke(service, :service1, *positionals, named_args: named)
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+
3
+ describe "Simple::Service::VERSION" do
4
+ it "returns a version number" do
5
+ expect(Simple::Service::VERSION).to match(/\d\.\d\.\d/)
6
+ end
7
+ end
@@ -0,0 +1,38 @@
1
+ ENV["RACK_ENV"] = "test"
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require "byebug"
5
+ require "rspec"
6
+
7
+ require "simplecov"
8
+
9
+ SimpleCov.start do
10
+ # return true to remove src from coverage
11
+ add_filter do |src|
12
+ next true if src.filename =~ /\/spec\//
13
+
14
+ false
15
+ end
16
+
17
+ # minimum_coverage 90
18
+ end
19
+
20
+ require "simple/service"
21
+
22
+ Dir.glob("./spec/support/**/*.rb").sort.each { |path| load path }
23
+
24
+ RSpec.configure do |config|
25
+ config.run_all_when_everything_filtered = true
26
+ config.filter_run focus: (ENV["CI"] != "true")
27
+ config.expect_with(:rspec) { |c| c.syntax = :expect }
28
+ config.order = "random"
29
+ config.example_status_persistence_file_path = ".rspec.data"
30
+
31
+ config.backtrace_exclusion_patterns << /spec\/support/
32
+ config.backtrace_exclusion_patterns << /spec\/helpers/
33
+ config.backtrace_exclusion_patterns << /spec_helper/
34
+
35
+ # config.around(:each) do |example|
36
+ # example.run
37
+ # end
38
+ end
@@ -0,0 +1,50 @@
1
+ # rubocop:disable Naming/UncommunicativeMethodParamName
2
+
3
+ module NoServiceModule
4
+ end
5
+
6
+ module SpecService
7
+ include Simple::Service
8
+
9
+ # This is service1
10
+ #
11
+ # Service 1 has a full description
12
+ def service1(a, b, c = "speed-of-light", d:, e: 2.781); end
13
+
14
+ # This is service2 (no full description)
15
+ def service2
16
+ "service2 return"
17
+ end
18
+
19
+ def service3
20
+ nil
21
+ end
22
+
23
+ private
24
+
25
+ def not_a_service; end
26
+ end
27
+
28
+ module InvokeTestService
29
+ include Simple::Service
30
+
31
+ def no_params
32
+ "service2 return"
33
+ end
34
+
35
+ def positional_params(a, b, c = "speed-of-light", e = 2.781)
36
+ [a, b, c, e]
37
+ end
38
+
39
+ def named_params(a:, b:, c: "speed-of-light", e: 2.781)
40
+ [a, b, c, e]
41
+ end
42
+
43
+ def mixed_optional_params(a, b = "default-b", c = "speed-of-light", e: 2.781)
44
+ [a, b, c, e]
45
+ end
46
+
47
+ def variadic_params(a, b = "queen bee", *args, e: 2.781)
48
+ [a, b, args, e]
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple-service
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - radiospiel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-12-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: expectation
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ description: Pretty simple and somewhat abstract service description
28
+ email: eno@radiospiel.org
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".gitignore"
34
+ - ".rubocop.yml"
35
+ - ".tm_properties"
36
+ - Gemfile
37
+ - Makefile
38
+ - README.md
39
+ - Rakefile
40
+ - VERSION
41
+ - bin/bundle
42
+ - bin/console
43
+ - bin/rake
44
+ - bin/rspec
45
+ - doc/Simple.html
46
+ - doc/Simple/Service.html
47
+ - doc/Simple/Service/Action.html
48
+ - doc/Simple/Service/Action/Comment.html
49
+ - doc/Simple/Service/Action/Comment/Extractor.html
50
+ - doc/Simple/Service/Action/IndieHash.html
51
+ - doc/Simple/Service/Action/MethodReflection.html
52
+ - doc/Simple/Service/Action/Parameter.html
53
+ - doc/Simple/Service/ArgumentError.html
54
+ - doc/Simple/Service/ClassMethods.html
55
+ - doc/Simple/Service/Context.html
56
+ - doc/Simple/Service/ContextMissingError.html
57
+ - doc/Simple/Service/ContextReadOnlyError.html
58
+ - doc/Simple/Service/ExtraArguments.html
59
+ - doc/Simple/Service/GemHelper.html
60
+ - doc/Simple/Service/MissingArguments.html
61
+ - doc/Simple/Service/NoSuchAction.html
62
+ - doc/_index.html
63
+ - doc/class_list.html
64
+ - doc/css/common.css
65
+ - doc/css/full_list.css
66
+ - doc/css/style.css
67
+ - doc/file.README.html
68
+ - doc/file_list.html
69
+ - doc/frames.html
70
+ - doc/index.html
71
+ - doc/js/app.js
72
+ - doc/js/full_list.js
73
+ - doc/js/jquery.js
74
+ - doc/method_list.html
75
+ - doc/top-level-namespace.html
76
+ - lib/simple-service.rb
77
+ - lib/simple/service.rb
78
+ - lib/simple/service/action.rb
79
+ - lib/simple/service/action/comment.rb
80
+ - lib/simple/service/action/indie_hash.rb
81
+ - lib/simple/service/action/method_reflection.rb
82
+ - lib/simple/service/action/parameter.rb
83
+ - lib/simple/service/context.rb
84
+ - lib/simple/service/errors.rb
85
+ - lib/simple/service/version.rb
86
+ - log/.gitkeep
87
+ - scripts/release
88
+ - scripts/release.rb
89
+ - scripts/stats
90
+ - scripts/watch
91
+ - simple-service.gemspec
92
+ - spec/simple/service/action_invoke2_spec.rb
93
+ - spec/simple/service/action_invoke_spec.rb
94
+ - spec/simple/service/action_spec.rb
95
+ - spec/simple/service/context_spec.rb
96
+ - spec/simple/service/service_spec.rb
97
+ - spec/simple/service/version_spec.rb
98
+ - spec/spec_helper.rb
99
+ - spec/support/spec_services.rb
100
+ homepage: http://github.com/radiospiel/simple-service
101
+ licenses: []
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '2.5'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubygems_version: 3.0.4
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Pretty simple and somewhat abstract service description
122
+ test_files:
123
+ - spec/simple/service/action_invoke2_spec.rb
124
+ - spec/simple/service/action_invoke_spec.rb
125
+ - spec/simple/service/action_spec.rb
126
+ - spec/simple/service/context_spec.rb
127
+ - spec/simple/service/service_spec.rb
128
+ - spec/simple/service/version_spec.rb
129
+ - spec/spec_helper.rb
130
+ - spec/support/spec_services.rb