simple-service 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -2
- data/Makefile +4 -11
- data/README.md +67 -2
- data/VERSION +1 -1
- data/doc/Simple.html +117 -0
- data/doc/Simple/Service.html +863 -0
- data/doc/Simple/Service/Action.html +1014 -0
- data/doc/Simple/Service/Action/Comment.html +451 -0
- data/doc/Simple/Service/Action/Comment/Extractor.html +347 -0
- data/doc/Simple/Service/Action/IndieHash.html +506 -0
- data/doc/Simple/Service/Action/MethodReflection.html +285 -0
- data/doc/Simple/Service/Action/Parameter.html +816 -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/_index.html +286 -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_list.html +56 -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 +539 -0
- data/doc/top-level-namespace.html +110 -0
- data/lib/simple/service.rb +56 -16
- data/lib/simple/service/action.rb +6 -6
- data/lib/simple/service/action/comment.rb +1 -1
- data/lib/simple/service/action/method_reflection.rb +1 -1
- data/lib/simple/service/context.rb +5 -5
- data/lib/simple/service/version.rb +2 -2
- metadata +33 -2
@@ -0,0 +1,110 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Top Level Namespace
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.20
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
pathId = "";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
|
41
|
+
|
42
|
+
<span class="title">Top Level Namespace</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Top Level Namespace
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
</div>
|
80
|
+
|
81
|
+
<h2>Defined Under Namespace</h2>
|
82
|
+
<p class="children">
|
83
|
+
|
84
|
+
|
85
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Simple.html" title="Simple (module)">Simple</a></span>
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
</p>
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
</div>
|
101
|
+
|
102
|
+
<div id="footer">
|
103
|
+
Generated on Tue Dec 3 13:46:26 2019 by
|
104
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
105
|
+
0.9.20 (ruby-2.5.1).
|
106
|
+
</div>
|
107
|
+
|
108
|
+
</div>
|
109
|
+
</body>
|
110
|
+
</html>
|
data/lib/simple/service.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module Simple #
|
1
|
+
module Simple # @private
|
2
2
|
end
|
3
3
|
|
4
4
|
require "expectation"
|
@@ -8,26 +8,60 @@ require_relative "service/action"
|
|
8
8
|
require_relative "service/context"
|
9
9
|
require_relative "service/version"
|
10
10
|
|
11
|
-
# The Simple::Service
|
11
|
+
# <b>The Simple::Service interface</b>
|
12
12
|
#
|
13
|
-
#
|
14
|
-
#
|
13
|
+
# This module implements the main API of the Simple::Service ruby gem.
|
14
|
+
#
|
15
|
+
# 1. <em>Marking a service module:</em> To turn a target module as a service module one must include <tt>Simple::Service</tt>
|
16
|
+
# into the target. This serves as a marker that this module is actually intended
|
17
|
+
# to provide one or more services. Example:
|
18
|
+
#
|
19
|
+
# module GodMode
|
20
|
+
# include Simple::Service
|
21
|
+
#
|
22
|
+
# # Build a universe.
|
23
|
+
# #
|
24
|
+
# # This comment will become part of the full description of the
|
25
|
+
# # "build_universe" service
|
26
|
+
# def build_universe(name, c: , pi: 3.14, e: 2.781)
|
27
|
+
# # at this point I realize that *I* am not God.
|
28
|
+
#
|
29
|
+
# 42 # Best try approach
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# 2. <em>Discover services:</em> To discover services in a service module use the #actions method. This returns a Hash
|
34
|
+
# of actions. [TODO] why a Hash?
|
35
|
+
#
|
36
|
+
# Simple::Service.actions(GodMode)
|
37
|
+
# => {:build_universe=>#<Simple::Service::Action...>, ...}
|
38
|
+
#
|
39
|
+
# 3. <em>Invoke a service:</em> run <tt>Simple::Service.invoke</tt> or <tt>Simple::Service.invoke2</tt>. You must set a context first.
|
40
|
+
#
|
41
|
+
# Simple::Service.with_context do
|
42
|
+
# Simple::Service.invoke(GodMode, :build_universe, "TestWorld", c: 1e9)
|
43
|
+
# end
|
44
|
+
# => 42
|
15
45
|
#
|
16
|
-
# This serves as a marker that this module is actually intended
|
17
|
-
# to be used as a service.
|
18
46
|
module Simple::Service
|
19
|
-
def self.included(klass) #
|
47
|
+
def self.included(klass) # @private
|
20
48
|
klass.extend ClassMethods
|
21
49
|
end
|
22
50
|
|
23
51
|
# returns true if the passed in object is a service module.
|
52
|
+
#
|
53
|
+
# A service must be a module, and it must include the Simple::Service module.
|
24
54
|
def self.service?(service)
|
25
|
-
|
55
|
+
verify_service! service
|
56
|
+
true
|
57
|
+
rescue ::ArgumentError
|
58
|
+
false
|
26
59
|
end
|
27
60
|
|
28
|
-
|
61
|
+
# Raises an error if the passed in object is not a service
|
62
|
+
def self.verify_service!(service) # @private
|
29
63
|
raise ::ArgumentError, "#{service.inspect} must be a Simple::Service, but is not even a Module" unless service.is_a?(Module)
|
30
|
-
raise ::ArgumentError, "#{service.inspect} must be a Simple::Service, did you 'include Simple::Service'" unless service?(
|
64
|
+
raise ::ArgumentError, "#{service.inspect} must be a Simple::Service, did you 'include Simple::Service'" unless service.include?(self)
|
31
65
|
end
|
32
66
|
|
33
67
|
# returns a Hash with all actions in the +service+ module
|
@@ -47,11 +81,15 @@ module Simple::Service
|
|
47
81
|
|
48
82
|
# invokes an action with a given +name+ in a service with +arguments+ and +params+.
|
49
83
|
#
|
50
|
-
#
|
84
|
+
# When calling +invoke+ using positional arguments (i.e. non-keyword arguments)
|
85
|
+
# they will be matched against positional arguments of the invoked method -
|
86
|
+
# but they will not be matched against named arguments.
|
51
87
|
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
88
|
+
# In other words: if the service implements an action "def foo(bar, baz:)", one can
|
89
|
+
# run it via
|
90
|
+
#
|
91
|
+
# - +Service.invoke("bar-value", baz: "baz-value")+, or via
|
92
|
+
# - +Service.invoke(bar: "bar-value", baz: "baz-value")+
|
55
93
|
#
|
56
94
|
# When there are not enough positional arguments to match the number of required
|
57
95
|
# positional arguments of the method we raise an ArgumentError.
|
@@ -59,7 +97,9 @@ module Simple::Service
|
|
59
97
|
# When there are more positional arguments provided than the number accepted
|
60
98
|
# by the method we raise an ArgumentError.
|
61
99
|
#
|
62
|
-
# Entries in the named_args Hash that are not defined in the action itself are ignored.
|
100
|
+
# Entries in the +named_args+ Hash that are not defined in the action itself are ignored.
|
101
|
+
#
|
102
|
+
# *Note:* You cannot call this method if the context is not set.
|
63
103
|
def self.invoke(service, name, *args, **named_args)
|
64
104
|
raise ContextMissingError, "Need to set context before calling ::Simple::Service.invoke" unless context
|
65
105
|
|
@@ -75,7 +115,7 @@ module Simple::Service
|
|
75
115
|
action(service, name).invoke2(args: args, flags: flags)
|
76
116
|
end
|
77
117
|
|
78
|
-
module ClassMethods #
|
118
|
+
module ClassMethods # @private
|
79
119
|
# returns a Hash of actions provided by the service module.
|
80
120
|
def __simple_service_actions__
|
81
121
|
@__simple_service_actions__ ||= Action.enumerate(service: self)
|
@@ -15,11 +15,11 @@ module Simple::Service
|
|
15
15
|
# rubocop:disable Metrics/ClassLength
|
16
16
|
|
17
17
|
class Action
|
18
|
-
IDENTIFIER_PATTERN = "[a-z][a-z0-9_]*" #
|
19
|
-
IDENTIFIER_REGEXP = Regexp.compile("\\A#{IDENTIFIER_PATTERN}\\z") #
|
18
|
+
IDENTIFIER_PATTERN = "[a-z][a-z0-9_]*" # @private
|
19
|
+
IDENTIFIER_REGEXP = Regexp.compile("\\A#{IDENTIFIER_PATTERN}\\z") # @private
|
20
20
|
|
21
21
|
# determines all services provided by the +service+ service module.
|
22
|
-
def self.enumerate(service:) #
|
22
|
+
def self.enumerate(service:) # @private
|
23
23
|
service.public_instance_methods(false)
|
24
24
|
.grep(IDENTIFIER_REGEXP)
|
25
25
|
.each_with_object({}) { |name, hsh| hsh[name] = Action.new(service, name) }
|
@@ -32,7 +32,7 @@ module Simple::Service
|
|
32
32
|
"#{service.name}##{name}"
|
33
33
|
end
|
34
34
|
|
35
|
-
def to_s #
|
35
|
+
def to_s # @private
|
36
36
|
full_name
|
37
37
|
end
|
38
38
|
|
@@ -41,7 +41,7 @@ module Simple::Service
|
|
41
41
|
@parameters ||= Parameter.reflect_on_method(service: service, name: name)
|
42
42
|
end
|
43
43
|
|
44
|
-
def initialize(service, name) #
|
44
|
+
def initialize(service, name) # @private
|
45
45
|
@service = service
|
46
46
|
@name = name
|
47
47
|
|
@@ -116,7 +116,7 @@ module Simple::Service
|
|
116
116
|
private
|
117
117
|
|
118
118
|
# returns an error if the keywords hash does not define all required keyword arguments.
|
119
|
-
def verify_required_args!(args, flags) #
|
119
|
+
def verify_required_args!(args, flags) # @private
|
120
120
|
@required_names ||= parameters.select(&:required?).map(&:name).map(&:to_s)
|
121
121
|
|
122
122
|
missing_parameters = @required_names - args.keys - flags.keys
|
@@ -32,8 +32,8 @@ module Simple::Service
|
|
32
32
|
# Also, once a value is set in the context it is not possible to change or
|
33
33
|
# unset it.
|
34
34
|
class Context
|
35
|
-
def initialize(hsh =
|
36
|
-
@hsh = hsh
|
35
|
+
def initialize(hsh = nil) # @private
|
36
|
+
@hsh = hsh || {}
|
37
37
|
end
|
38
38
|
|
39
39
|
# returns a new Context object, which merges the values in the +overlay+
|
@@ -52,9 +52,9 @@ module Simple::Service
|
|
52
52
|
|
53
53
|
private
|
54
54
|
|
55
|
-
IDENTIFIER_PATTERN = "[a-z][a-z0-9_]*" #
|
56
|
-
IDENTIFIER_REGEXP = Regexp.compile("\\A#{IDENTIFIER_PATTERN}\\z") #
|
57
|
-
ASSIGNMENT_REGEXP = Regexp.compile("\\A(#{IDENTIFIER_PATTERN})=\\z") #
|
55
|
+
IDENTIFIER_PATTERN = "[a-z][a-z0-9_]*" # @private
|
56
|
+
IDENTIFIER_REGEXP = Regexp.compile("\\A#{IDENTIFIER_PATTERN}\\z") # @private
|
57
|
+
ASSIGNMENT_REGEXP = Regexp.compile("\\A(#{IDENTIFIER_PATTERN})=\\z") # @private
|
58
58
|
|
59
59
|
def method_missing(sym, *args, &block)
|
60
60
|
raise ArgumentError, "Block given" if block
|
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.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- radiospiel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: expectation
|
@@ -42,6 +42,37 @@ files:
|
|
42
42
|
- bin/console
|
43
43
|
- bin/rake
|
44
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
|
45
76
|
- lib/simple-service.rb
|
46
77
|
- lib/simple/service.rb
|
47
78
|
- lib/simple/service/action.rb
|