simple-service 0.1.1 → 0.1.6
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/.rubocop.yml +7 -0
- data/.tm_properties +1 -1
- data/Makefile +8 -0
- data/README.md +68 -1
- data/TODO.txt +3 -0
- data/VERSION +1 -1
- data/doc/Simple.html +117 -0
- data/doc/Simple/Service.html +865 -0
- data/doc/Simple/Service/Action.html +923 -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/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 +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.rb +161 -56
- data/lib/simple/service/action.rb +104 -107
- data/lib/simple/service/action/comment.rb +3 -1
- data/lib/simple/service/action/method_reflection.rb +3 -3
- data/lib/simple/service/action/parameter.rb +3 -7
- data/lib/simple/service/context.rb +69 -27
- data/lib/simple/service/errors.rb +54 -0
- data/lib/simple/service/version.rb +7 -2
- data/scripts/stats +2 -1
- data/spec/simple/service/action_invoke3_spec.rb +266 -0
- data/spec/simple/service/action_invoke_spec.rb +237 -0
- data/spec/simple/service/action_spec.rb +51 -0
- data/spec/simple/service/context_spec.rb +39 -7
- data/spec/simple/service/service_spec.rb +158 -0
- data/spec/simple/service/version_spec.rb +7 -0
- data/spec/spec_helper.rb +15 -2
- data/spec/support/spec_services.rb +58 -0
- metadata +48 -6
- data/lib/simple.rb +0 -2
- data/spec/support/004_simplecov.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 903d43626ea1853a44478fd58d6aef0a4e86374745e9a5732e127ab85fcd4437
|
4
|
+
data.tar.gz: ed5f2caa57468945b72bcf805c0ff3e2afd7df654ea03387a59fa16ea136ad19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ab49e773b69b41e844a73da66f7ab06ca90f0d4edc097a4d44bc8457272040acd428fc37e3128a6e662f18bab30fb6d0e8a396c40eed6eccb2dd316171c5b1a
|
7
|
+
data.tar.gz: b06385441ec3d0ce87aba8095e30cb7ab07f871c6507ae133b611eab0f370458c378d5f1ffd27111221b3ca75096ca0ff41bc1c6b61ab1f40cfebe45b1a5ac81
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -10,6 +10,10 @@ AllCops:
|
|
10
10
|
- 'Rakefile'
|
11
11
|
- 'scripts/*.rb'
|
12
12
|
|
13
|
+
Metrics/BlockLength:
|
14
|
+
Exclude:
|
15
|
+
- 'spec/**/*'
|
16
|
+
|
13
17
|
Metrics/LineLength:
|
14
18
|
Max: 140
|
15
19
|
|
@@ -94,3 +98,6 @@ Style/DoubleNegation:
|
|
94
98
|
|
95
99
|
Style/ParallelAssignment:
|
96
100
|
Enabled: false
|
101
|
+
|
102
|
+
Style/CommentedKeyword:
|
103
|
+
Enabled: false
|
data/.tm_properties
CHANGED
@@ -1 +1 @@
|
|
1
|
-
excludeDirectories = "{_build,coverage,assets/node_modules,node_modules,deps,db,cover,priv/static,storage,github,vendor,arena,}"
|
1
|
+
excludeDirectories = "{_build,coverage,rdoc,assets/node_modules,node_modules,deps,db,cover,priv/static,storage,github,vendor,arena,}"
|
data/Makefile
CHANGED
data/README.md
CHANGED
@@ -1 +1,68 @@
|
|
1
|
-
# simple-service –
|
1
|
+
# simple-service – at your service!
|
2
|
+
|
3
|
+
The `simple-service` ruby gem helps you turn your ruby source code into *"services".* A service is a module which provides interfaces to one or more methods (*"actions"*) that implement business logic.
|
4
|
+
|
5
|
+
While one could, of course, call any such method any way one wants, this gem lets you
|
6
|
+
|
7
|
+
- discover available services (their names, their parameters (name, type, default values), comments - see `Simple::Service.actions`;
|
8
|
+
- an interface to "run" (or "execute") a service, with separation from any other parallel runs - see `Simple::Service.invoke` and `Simple::Service.invoke2`;
|
9
|
+
- a semi-constant "*environment*" for the duration of an execution;
|
10
|
+
- ![TODO](https://badgen.net/badge/TODO/high?color=red) a normalized interface to check whether or not a specific service is allowed to run based on the current context.
|
11
|
+
|
12
|
+
These features allow *simple-service* to serve as a building block for other tools. It is currently in used in:
|
13
|
+
|
14
|
+
- *simple-httpd*: a simple web server
|
15
|
+
- *simple-cli*: the best way to build a ruby CLI.
|
16
|
+
|
17
|
+
## Example
|
18
|
+
|
19
|
+
### Defining a service
|
20
|
+
|
21
|
+
A service module can define one or more services. The following example defines a single service:
|
22
|
+
|
23
|
+
# A service which constructs universes with different physics.
|
24
|
+
module GodMode
|
25
|
+
include Simple::Service
|
26
|
+
|
27
|
+
# Build a universe.
|
28
|
+
#
|
29
|
+
# This comment will become part of the full description of the
|
30
|
+
# "build_universe" service
|
31
|
+
def build_universe(name, c: , pi: 3.14, e: 2.781)
|
32
|
+
# at this point I realize that *I* am not God.
|
33
|
+
|
34
|
+
42 # Best try approach
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
### Running a service
|
39
|
+
|
40
|
+
To run the service one uses one of two different methods. If you have an **anonymous array** of arguments - think command line interface - you would call it like this:
|
41
|
+
|
42
|
+
Simple::Service.invoke GodMode, :build_universe,
|
43
|
+
"My Universe",
|
44
|
+
c: 3e8
|
45
|
+
|
46
|
+
If the calling site, however, has **named arguments** (in a Hash), one would invoke a service using `invoke2`. This is used for HTTPD integration (with `simple-httpd`.)
|
47
|
+
|
48
|
+
args = { name: "My Universe", c: 299792458}
|
49
|
+
Simple::Service.invoke2 GodMode,
|
50
|
+
:build_universe,
|
51
|
+
args: args
|
52
|
+
|
53
|
+
Note that you must set a context during the execution; this is done by `with_context`. A `nil` context is a valid value which describes an empty context.
|
54
|
+
|
55
|
+
A full example could therefore look like:
|
56
|
+
|
57
|
+
Simple::Service.with_context(nil) do
|
58
|
+
args = { name: "My Universe", c: 299792458}
|
59
|
+
Simple::Service.invoke2 GodMode,
|
60
|
+
:build_universe,
|
61
|
+
args: args
|
62
|
+
end
|
63
|
+
|
64
|
+
## History
|
65
|
+
|
66
|
+
Historically, the `simple-cli` gem implemented an easy way to build a CLI application, and therefore needed a way to reflect on existing code to determine which methods to call, which arguments they support etc. Also, the `postjob` job queue calls a specific method based on its name and an arguments Array or Hash, which is being read from a database. Finally, when I tried to extent `postjob` with a HTTP interface I discovered that a similar feature would again be extremely useful.
|
67
|
+
|
68
|
+
I therefore extracted these features into a standalone gem.
|
data/TODO.txt
ADDED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.6
|
data/doc/Simple.html
ADDED
@@ -0,0 +1,117 @@
|
|
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
|
+
Module: Simple
|
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 = "Simple";
|
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 (S)</a> »
|
40
|
+
|
41
|
+
|
42
|
+
<span class="title">Simple</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>Module: Simple
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<dl>
|
80
|
+
<dt>Defined in:</dt>
|
81
|
+
<dd>lib/simple/service.rb<span class="defines">,<br />
|
82
|
+
lib/simple/service/version.rb</span>
|
83
|
+
</dd>
|
84
|
+
</dl>
|
85
|
+
|
86
|
+
</div>
|
87
|
+
|
88
|
+
<h2>Defined Under Namespace</h2>
|
89
|
+
<p class="children">
|
90
|
+
|
91
|
+
|
92
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Simple/Service.html" title="Simple::Service (module)">Service</a></span>
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
</p>
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
</div>
|
108
|
+
|
109
|
+
<div id="footer">
|
110
|
+
Generated on Wed Dec 4 22:57:12 2019 by
|
111
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
112
|
+
0.9.20 (ruby-2.5.1).
|
113
|
+
</div>
|
114
|
+
|
115
|
+
</div>
|
116
|
+
</body>
|
117
|
+
</html>
|
@@ -0,0 +1,865 @@
|
|
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
|
+
Module: Simple::Service
|
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 = "Simple::Service";
|
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 (S)</a> »
|
40
|
+
<span class='title'><span class='object_link'><a href="../Simple.html" title="Simple (module)">Simple</a></span></span>
|
41
|
+
»
|
42
|
+
<span class="title">Service</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>Module: Simple::Service
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<dl>
|
80
|
+
<dt>Defined in:</dt>
|
81
|
+
<dd>lib/simple/service.rb<span class="defines">,<br />
|
82
|
+
lib/simple/service/action.rb,<br /> lib/simple/service/action.rb,<br /> lib/simple/service/errors.rb,<br /> lib/simple/service/context.rb,<br /> lib/simple/service/context.rb,<br /> lib/simple/service/version.rb</span>
|
83
|
+
</dd>
|
84
|
+
</dl>
|
85
|
+
|
86
|
+
</div>
|
87
|
+
|
88
|
+
<h2>Overview</h2><div class="docstring">
|
89
|
+
<div class="discussion">
|
90
|
+
|
91
|
+
<p><strong>The Simple::Service interface</strong></p>
|
92
|
+
|
93
|
+
<p>This module implements the main API of the Simple::Service ruby gem.</p>
|
94
|
+
<ol><li>
|
95
|
+
<p><em>Marking a service module:</em> To turn a target module as a service module one must include <code>Simple::Service</code> into the target. This serves as a marker that this module is actually intended to provide one or more services. Example:</p>
|
96
|
+
|
97
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>module</span> <span class='const'>GodMode</span>
|
98
|
+
<span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="../Simple.html" title="Simple (module)">Simple</a></span></span><span class='op'>::</span><span class='const'>Service</span>
|
99
|
+
|
100
|
+
<span class='comment'># Build a universe.
|
101
|
+
</span> <span class='comment'>#
|
102
|
+
</span> <span class='comment'># This comment will become part of the full description of the
|
103
|
+
</span> <span class='comment'># "build_universe" service
|
104
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_build_universe'>build_universe</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='label'>c:</span> <span class='comma'>,</span> <span class='label'>pi:</span> <span class='float'>3.14</span><span class='comma'>,</span> <span class='label'>e:</span> <span class='float'>2.781</span><span class='rparen'>)</span>
|
105
|
+
<span class='comment'># at this point I realize that *I* am not God.
|
106
|
+
</span>
|
107
|
+
<span class='int'>42</span> <span class='comment'># Best try approach
|
108
|
+
</span> <span class='kw'>end</span>
|
109
|
+
<span class='kw'>end</span>
|
110
|
+
</code></pre>
|
111
|
+
</li><li>
|
112
|
+
<p><em>Discover services:</em> To discover services in a service module use the #actions method. This returns a Hash of actions. </p>
|
113
|
+
|
114
|
+
<pre class="code ruby"><code class="ruby">Simple::Service.actions(GodMode)
|
115
|
+
=> {:build_universe=>#<Simple::Service::Action...>, ...}
|
116
|
+
</code></pre>
|
117
|
+
</li></ol>
|
118
|
+
|
119
|
+
<p>TODO: why a Hash? It feels much better if Simple::Service.actions returns an array of names.</p>
|
120
|
+
<ol><li>
|
121
|
+
<p><em>Invoke a service:</em> run <code>Simple::Service.invoke3</code> or <code>Simple::Service.invoke</code>. You must set a context first.</p>
|
122
|
+
|
123
|
+
<pre class="code ruby"><code class="ruby">Simple::Service.with_context do
|
124
|
+
Simple::Service.invoke3(GodMode, :build_universe, "TestWorld", c: 1e9)
|
125
|
+
end
|
126
|
+
=> 42
|
127
|
+
</code></pre>
|
128
|
+
</li></ol>
|
129
|
+
|
130
|
+
|
131
|
+
</div>
|
132
|
+
</div>
|
133
|
+
<div class="tags">
|
134
|
+
|
135
|
+
|
136
|
+
</div><h2>Defined Under Namespace</h2>
|
137
|
+
<p class="children">
|
138
|
+
|
139
|
+
|
140
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Service/ClassMethods.html" title="Simple::Service::ClassMethods (module)">ClassMethods</a></span>, <span class='object_link'><a href="Service/GemHelper.html" title="Simple::Service::GemHelper (module)">GemHelper</a></span>
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Service/Action.html" title="Simple::Service::Action (class)">Action</a></span>, <span class='object_link'><a href="Service/ArgumentError.html" title="Simple::Service::ArgumentError (class)">ArgumentError</a></span>, <span class='object_link'><a href="Service/Context.html" title="Simple::Service::Context (class)">Context</a></span>, <span class='object_link'><a href="Service/ContextMissingError.html" title="Simple::Service::ContextMissingError (class)">ContextMissingError</a></span>, <span class='object_link'><a href="Service/ContextReadOnlyError.html" title="Simple::Service::ContextReadOnlyError (class)">ContextReadOnlyError</a></span>, <span class='object_link'><a href="Service/ExtraArguments.html" title="Simple::Service::ExtraArguments (class)">ExtraArguments</a></span>, <span class='object_link'><a href="Service/MissingArguments.html" title="Simple::Service::MissingArguments (class)">MissingArguments</a></span>, <span class='object_link'><a href="Service/NoSuchAction.html" title="Simple::Service::NoSuchAction (class)">NoSuchAction</a></span>
|
145
|
+
|
146
|
+
|
147
|
+
</p>
|
148
|
+
|
149
|
+
|
150
|
+
<h2>
|
151
|
+
Constant Summary
|
152
|
+
<small><a href="#" class="constants_summary_toggle">collapse</a></small>
|
153
|
+
</h2>
|
154
|
+
|
155
|
+
<dl class="constants">
|
156
|
+
|
157
|
+
<dt id="VERSION-constant" class="">VERSION =
|
158
|
+
|
159
|
+
</dt>
|
160
|
+
<dd><pre class="code"><span class='const'><span class='object_link'><a href="Service/GemHelper.html" title="Simple::Service::GemHelper (module)">GemHelper</a></span></span><span class='period'>.</span><span class='id identifier rubyid_version'><span class='object_link'><a href="Service/GemHelper.html#version-instance_method" title="Simple::Service::GemHelper#version (method)">version</a></span></span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>simple-service</span><span class='tstring_end'>"</span></span></pre></dd>
|
161
|
+
|
162
|
+
</dl>
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
<h2>
|
173
|
+
Class Method Summary
|
174
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
175
|
+
</h2>
|
176
|
+
|
177
|
+
<ul class="summary">
|
178
|
+
|
179
|
+
<li class="public ">
|
180
|
+
<span class="summary_signature">
|
181
|
+
|
182
|
+
<a href="#action-class_method" title="action (class method)">.<strong>action</strong>(service, name) ⇒ Object </a>
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
</span>
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
<span class="summary_desc"><div class='inline'>
|
197
|
+
<p>returns the action with the given name.</p>
|
198
|
+
</div></span>
|
199
|
+
|
200
|
+
</li>
|
201
|
+
|
202
|
+
|
203
|
+
<li class="public ">
|
204
|
+
<span class="summary_signature">
|
205
|
+
|
206
|
+
<a href="#actions-class_method" title="actions (class method)">.<strong>actions</strong>(service) ⇒ Object </a>
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
</span>
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
<span class="summary_desc"><div class='inline'>
|
221
|
+
<p>returns a Hash with all actions in the <code>service</code> module.</p>
|
222
|
+
</div></span>
|
223
|
+
|
224
|
+
</li>
|
225
|
+
|
226
|
+
|
227
|
+
<li class="public ">
|
228
|
+
<span class="summary_signature">
|
229
|
+
|
230
|
+
<a href="#context-class_method" title="context (class method)">.<strong>context</strong> ⇒ Object </a>
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
</span>
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
|
244
|
+
<span class="summary_desc"><div class='inline'>
|
245
|
+
<p>Returns the current context.</p>
|
246
|
+
</div></span>
|
247
|
+
|
248
|
+
</li>
|
249
|
+
|
250
|
+
|
251
|
+
<li class="public ">
|
252
|
+
<span class="summary_signature">
|
253
|
+
|
254
|
+
<a href="#included-class_method" title="included (class method)">.<strong>included</strong>(klass) ⇒ Object </a>
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
</span>
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
269
|
+
|
270
|
+
</li>
|
271
|
+
|
272
|
+
|
273
|
+
<li class="public ">
|
274
|
+
<span class="summary_signature">
|
275
|
+
|
276
|
+
<a href="#invoke-class_method" title="invoke (class method)">.<strong>invoke</strong>(service, name, args: {}, flags: {}) ⇒ Object </a>
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
</span>
|
281
|
+
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
|
290
|
+
<span class="summary_desc"><div class='inline'>
|
291
|
+
<p><strong>Note:</strong> You cannot call this method if the context is not set.</p>
|
292
|
+
</div></span>
|
293
|
+
|
294
|
+
</li>
|
295
|
+
|
296
|
+
|
297
|
+
<li class="public ">
|
298
|
+
<span class="summary_signature">
|
299
|
+
|
300
|
+
<a href="#invoke3-class_method" title="invoke3 (class method)">.<strong>invoke3</strong>(service, name, *args, **flags) ⇒ Object </a>
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
</span>
|
305
|
+
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
|
314
|
+
<span class="summary_desc"><div class='inline'>
|
315
|
+
<p>invokes an action with a given <code>name</code> in a service with <code>args</code> and <code>flags</code>.</p>
|
316
|
+
</div></span>
|
317
|
+
|
318
|
+
</li>
|
319
|
+
|
320
|
+
|
321
|
+
<li class="public ">
|
322
|
+
<span class="summary_signature">
|
323
|
+
|
324
|
+
<a href="#service%3F-class_method" title="service? (class method)">.<strong>service?</strong>(service) ⇒ Boolean </a>
|
325
|
+
|
326
|
+
|
327
|
+
|
328
|
+
</span>
|
329
|
+
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
|
338
|
+
<span class="summary_desc"><div class='inline'>
|
339
|
+
<p>returns true if the passed in object is a service module.</p>
|
340
|
+
</div></span>
|
341
|
+
|
342
|
+
</li>
|
343
|
+
|
344
|
+
|
345
|
+
<li class="public ">
|
346
|
+
<span class="summary_signature">
|
347
|
+
|
348
|
+
<a href="#verify_service!-class_method" title="verify_service! (class method)">.<strong>verify_service!</strong>(service) ⇒ Object </a>
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
</span>
|
353
|
+
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
|
362
|
+
<span class="summary_desc"><div class='inline'>
|
363
|
+
<p>Raises an error if the passed in object is not a service.</p>
|
364
|
+
</div></span>
|
365
|
+
|
366
|
+
</li>
|
367
|
+
|
368
|
+
|
369
|
+
<li class="public ">
|
370
|
+
<span class="summary_signature">
|
371
|
+
|
372
|
+
<a href="#with_context-class_method" title="with_context (class method)">.<strong>with_context</strong>(ctx = nil, &block) ⇒ Object </a>
|
373
|
+
|
374
|
+
|
375
|
+
|
376
|
+
</span>
|
377
|
+
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
|
386
|
+
<span class="summary_desc"><div class='inline'>
|
387
|
+
<p>yields a block with a given context, and restores the previous context object afterwards.</p>
|
388
|
+
</div></span>
|
389
|
+
|
390
|
+
</li>
|
391
|
+
|
392
|
+
|
393
|
+
</ul>
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
|
398
|
+
<div id="class_method_details" class="method_details_list">
|
399
|
+
<h2>Class Method Details</h2>
|
400
|
+
|
401
|
+
|
402
|
+
<div class="method_details first">
|
403
|
+
<h3 class="signature first" id="action-class_method">
|
404
|
+
|
405
|
+
.<strong>action</strong>(service, name) ⇒ <tt>Object</tt>
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
</h3><div class="docstring">
|
412
|
+
<div class="discussion">
|
413
|
+
|
414
|
+
<p>returns the action with the given name.</p>
|
415
|
+
|
416
|
+
|
417
|
+
</div>
|
418
|
+
</div>
|
419
|
+
<div class="tags">
|
420
|
+
|
421
|
+
|
422
|
+
</div><table class="source_code">
|
423
|
+
<tr>
|
424
|
+
<td>
|
425
|
+
<pre class="lines">
|
426
|
+
|
427
|
+
|
428
|
+
78
|
429
|
+
79
|
430
|
+
80
|
431
|
+
81
|
432
|
+
82
|
433
|
+
83</pre>
|
434
|
+
</td>
|
435
|
+
<td>
|
436
|
+
<pre class="code"><span class="info file"># File 'lib/simple/service.rb', line 78</span>
|
437
|
+
|
438
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_action'>action</span><span class='lparen'>(</span><span class='id identifier rubyid_service'>service</span><span class='comma'>,</span> <span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
439
|
+
<span class='id identifier rubyid_actions'>actions</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_actions'>actions</span><span class='lparen'>(</span><span class='id identifier rubyid_service'>service</span><span class='rparen'>)</span>
|
440
|
+
<span class='id identifier rubyid_actions'>actions</span><span class='lbracket'>[</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='kw'>begin</span>
|
441
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='op'>::</span><span class='const'><span class='object_link'><a href="../Simple.html" title="Simple (module)">Simple</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="" title="Simple::Service (module)">Service</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Service/NoSuchAction.html" title="Simple::Service::NoSuchAction (class)">NoSuchAction</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Service/NoSuchAction.html#initialize-instance_method" title="Simple::Service::NoSuchAction#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_service'>service</span><span class='comma'>,</span> <span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
442
|
+
<span class='kw'>end</span>
|
443
|
+
<span class='kw'>end</span></pre>
|
444
|
+
</td>
|
445
|
+
</tr>
|
446
|
+
</table>
|
447
|
+
</div>
|
448
|
+
|
449
|
+
<div class="method_details ">
|
450
|
+
<h3 class="signature " id="actions-class_method">
|
451
|
+
|
452
|
+
.<strong>actions</strong>(service) ⇒ <tt>Object</tt>
|
453
|
+
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
|
458
|
+
</h3><div class="docstring">
|
459
|
+
<div class="discussion">
|
460
|
+
|
461
|
+
<p>returns a Hash with all actions in the <code>service</code> module</p>
|
462
|
+
|
463
|
+
|
464
|
+
</div>
|
465
|
+
</div>
|
466
|
+
<div class="tags">
|
467
|
+
|
468
|
+
|
469
|
+
</div><table class="source_code">
|
470
|
+
<tr>
|
471
|
+
<td>
|
472
|
+
<pre class="lines">
|
473
|
+
|
474
|
+
|
475
|
+
71
|
476
|
+
72
|
477
|
+
73
|
478
|
+
74
|
479
|
+
75</pre>
|
480
|
+
</td>
|
481
|
+
<td>
|
482
|
+
<pre class="code"><span class="info file"># File 'lib/simple/service.rb', line 71</span>
|
483
|
+
|
484
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_actions'>actions</span><span class='lparen'>(</span><span class='id identifier rubyid_service'>service</span><span class='rparen'>)</span>
|
485
|
+
<span class='id identifier rubyid_verify_service!'>verify_service!</span><span class='lparen'>(</span><span class='id identifier rubyid_service'>service</span><span class='rparen'>)</span>
|
486
|
+
|
487
|
+
<span class='id identifier rubyid_service'>service</span><span class='period'>.</span><span class='id identifier rubyid___simple_service_actions__'>__simple_service_actions__</span>
|
488
|
+
<span class='kw'>end</span></pre>
|
489
|
+
</td>
|
490
|
+
</tr>
|
491
|
+
</table>
|
492
|
+
</div>
|
493
|
+
|
494
|
+
<div class="method_details ">
|
495
|
+
<h3 class="signature " id="context-class_method">
|
496
|
+
|
497
|
+
.<strong>context</strong> ⇒ <tt>Object</tt>
|
498
|
+
|
499
|
+
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
</h3><div class="docstring">
|
504
|
+
<div class="discussion">
|
505
|
+
|
506
|
+
<p>Returns the current context.</p>
|
507
|
+
|
508
|
+
|
509
|
+
</div>
|
510
|
+
</div>
|
511
|
+
<div class="tags">
|
512
|
+
|
513
|
+
|
514
|
+
</div><table class="source_code">
|
515
|
+
<tr>
|
516
|
+
<td>
|
517
|
+
<pre class="lines">
|
518
|
+
|
519
|
+
|
520
|
+
3
|
521
|
+
4
|
522
|
+
5</pre>
|
523
|
+
</td>
|
524
|
+
<td>
|
525
|
+
<pre class="code"><span class="info file"># File 'lib/simple/service/context.rb', line 3</span>
|
526
|
+
|
527
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_context'>context</span>
|
528
|
+
<span class='const'>Thread</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='lbracket'>[</span><span class='symbol'>:"Simple::Service.context"</span><span class='rbracket'>]</span>
|
529
|
+
<span class='kw'>end</span></pre>
|
530
|
+
</td>
|
531
|
+
</tr>
|
532
|
+
</table>
|
533
|
+
</div>
|
534
|
+
|
535
|
+
<div class="method_details ">
|
536
|
+
<h3 class="signature " id="included-class_method">
|
537
|
+
|
538
|
+
.<strong>included</strong>(klass) ⇒ <tt>Object</tt>
|
539
|
+
|
540
|
+
|
541
|
+
|
542
|
+
|
543
|
+
|
544
|
+
</h3><table class="source_code">
|
545
|
+
<tr>
|
546
|
+
<td>
|
547
|
+
<pre class="lines">
|
548
|
+
|
549
|
+
|
550
|
+
50
|
551
|
+
51
|
552
|
+
52</pre>
|
553
|
+
</td>
|
554
|
+
<td>
|
555
|
+
<pre class="code"><span class="info file"># File 'lib/simple/service.rb', line 50</span>
|
556
|
+
|
557
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_included'>included</span><span class='lparen'>(</span><span class='id identifier rubyid_klass'>klass</span><span class='rparen'>)</span> <span class='comment'># @private
|
558
|
+
</span> <span class='id identifier rubyid_klass'>klass</span><span class='period'>.</span><span class='id identifier rubyid_extend'>extend</span> <span class='const'><span class='object_link'><a href="Service/ClassMethods.html" title="Simple::Service::ClassMethods (module)">ClassMethods</a></span></span>
|
559
|
+
<span class='kw'>end</span></pre>
|
560
|
+
</td>
|
561
|
+
</tr>
|
562
|
+
</table>
|
563
|
+
</div>
|
564
|
+
|
565
|
+
<div class="method_details ">
|
566
|
+
<h3 class="signature " id="invoke-class_method">
|
567
|
+
|
568
|
+
.<strong>invoke</strong>(service, name, args: {}, flags: {}) ⇒ <tt>Object</tt>
|
569
|
+
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
|
574
|
+
</h3><div class="docstring">
|
575
|
+
<div class="discussion">
|
576
|
+
|
577
|
+
<p><strong>Note:</strong> You cannot call this method if the context is not set.</p>
|
578
|
+
|
579
|
+
|
580
|
+
</div>
|
581
|
+
</div>
|
582
|
+
<div class="tags">
|
583
|
+
|
584
|
+
<p class="tag_title">Raises:</p>
|
585
|
+
<ul class="raise">
|
586
|
+
|
587
|
+
<li>
|
588
|
+
|
589
|
+
|
590
|
+
<span class='type'>(<tt><span class='object_link'><a href="Service/ContextMissingError.html" title="Simple::Service::ContextMissingError (class)">ContextMissingError</a></span></tt>)</span>
|
591
|
+
|
592
|
+
|
593
|
+
|
594
|
+
</li>
|
595
|
+
|
596
|
+
</ul>
|
597
|
+
|
598
|
+
</div><table class="source_code">
|
599
|
+
<tr>
|
600
|
+
<td>
|
601
|
+
<pre class="lines">
|
602
|
+
|
603
|
+
|
604
|
+
141
|
605
|
+
142
|
606
|
+
143
|
607
|
+
144
|
608
|
+
145
|
609
|
+
146
|
610
|
+
147
|
611
|
+
148
|
612
|
+
149</pre>
|
613
|
+
</td>
|
614
|
+
<td>
|
615
|
+
<pre class="code"><span class="info file"># File 'lib/simple/service.rb', line 141</span>
|
616
|
+
|
617
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_invoke'>invoke</span><span class='lparen'>(</span><span class='id identifier rubyid_service'>service</span><span class='comma'>,</span> <span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='label'>args:</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='label'>flags:</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
|
618
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="Service/ContextMissingError.html" title="Simple::Service::ContextMissingError (class)">ContextMissingError</a></span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Need to set context before calling ::Simple::Service.invoke3</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_context'>context</span>
|
619
|
+
|
620
|
+
<span class='id identifier rubyid_expect!'>expect!</span> <span class='id identifier rubyid_args'>args</span> <span class='op'>=></span> <span class='lbracket'>[</span><span class='const'>Hash</span><span class='comma'>,</span> <span class='const'>Array</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>flags:</span> <span class='const'>Hash</span>
|
621
|
+
<span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_key'>key</span><span class='op'>|</span> <span class='id identifier rubyid_expect!'>expect!</span> <span class='id identifier rubyid_key'>key</span> <span class='op'>=></span> <span class='const'>String</span> <span class='rbrace'>}</span> <span class='kw'>if</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
|
622
|
+
<span class='id identifier rubyid_flags'>flags</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_key'>key</span><span class='op'>|</span> <span class='id identifier rubyid_expect!'>expect!</span> <span class='id identifier rubyid_key'>key</span> <span class='op'>=></span> <span class='const'>String</span> <span class='rbrace'>}</span>
|
623
|
+
|
624
|
+
<span class='id identifier rubyid_action'>action</span><span class='lparen'>(</span><span class='id identifier rubyid_service'>service</span><span class='comma'>,</span> <span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_invoke'>invoke</span><span class='lparen'>(</span><span class='label'>args:</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='label'>flags:</span> <span class='id identifier rubyid_flags'>flags</span><span class='rparen'>)</span>
|
625
|
+
<span class='kw'>end</span></pre>
|
626
|
+
</td>
|
627
|
+
</tr>
|
628
|
+
</table>
|
629
|
+
</div>
|
630
|
+
|
631
|
+
<div class="method_details ">
|
632
|
+
<h3 class="signature " id="invoke3-class_method">
|
633
|
+
|
634
|
+
.<strong>invoke3</strong>(service, name, *args, **flags) ⇒ <tt>Object</tt>
|
635
|
+
|
636
|
+
|
637
|
+
|
638
|
+
|
639
|
+
|
640
|
+
</h3><div class="docstring">
|
641
|
+
<div class="discussion">
|
642
|
+
|
643
|
+
<p>invokes an action with a given <code>name</code> in a service with <code>args</code> and <code>flags</code>.</p>
|
644
|
+
|
645
|
+
<p>This is a helper method which one can use to easily call an action from ruby source code.</p>
|
646
|
+
|
647
|
+
<p>As the main purpose of this module is to call services with outside data, the <code>.invoke</code> action is usually preferred.</p>
|
648
|
+
|
649
|
+
<p><strong>Note:</strong> You cannot call this method if the context is not set.</p>
|
650
|
+
|
651
|
+
|
652
|
+
</div>
|
653
|
+
</div>
|
654
|
+
<div class="tags">
|
655
|
+
|
656
|
+
|
657
|
+
</div><table class="source_code">
|
658
|
+
<tr>
|
659
|
+
<td>
|
660
|
+
<pre class="lines">
|
661
|
+
|
662
|
+
|
663
|
+
94
|
664
|
+
95
|
665
|
+
96
|
666
|
+
97</pre>
|
667
|
+
</td>
|
668
|
+
<td>
|
669
|
+
<pre class="code"><span class="info file"># File 'lib/simple/service.rb', line 94</span>
|
670
|
+
|
671
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_invoke3'>invoke3</span><span class='lparen'>(</span><span class='id identifier rubyid_service'>service</span><span class='comma'>,</span> <span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_flags'>flags</span><span class='rparen'>)</span>
|
672
|
+
<span class='id identifier rubyid_flags'>flags</span> <span class='op'>=</span> <span class='id identifier rubyid_flags'>flags</span><span class='period'>.</span><span class='id identifier rubyid_each_with_object'>each_with_object</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='lparen'>(</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span> <span class='id identifier rubyid_v'>v</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_hsh'>hsh</span><span class='op'>|</span> <span class='id identifier rubyid_hsh'>hsh</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_v'>v</span> <span class='rbrace'>}</span>
|
673
|
+
<span class='id identifier rubyid_invoke'>invoke</span> <span class='id identifier rubyid_service'>service</span><span class='comma'>,</span> <span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='label'>args:</span> <span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='label'>flags:</span> <span class='id identifier rubyid_flags'>flags</span>
|
674
|
+
<span class='kw'>end</span></pre>
|
675
|
+
</td>
|
676
|
+
</tr>
|
677
|
+
</table>
|
678
|
+
</div>
|
679
|
+
|
680
|
+
<div class="method_details ">
|
681
|
+
<h3 class="signature " id="service?-class_method">
|
682
|
+
|
683
|
+
.<strong>service?</strong>(service) ⇒ <tt>Boolean</tt>
|
684
|
+
|
685
|
+
|
686
|
+
|
687
|
+
|
688
|
+
|
689
|
+
</h3><div class="docstring">
|
690
|
+
<div class="discussion">
|
691
|
+
|
692
|
+
<p>returns true if the passed in object is a service module.</p>
|
693
|
+
|
694
|
+
<p>A service must be a module, and it must include the Simple::Service module.</p>
|
695
|
+
|
696
|
+
|
697
|
+
</div>
|
698
|
+
</div>
|
699
|
+
<div class="tags">
|
700
|
+
|
701
|
+
<p class="tag_title">Returns:</p>
|
702
|
+
<ul class="return">
|
703
|
+
|
704
|
+
<li>
|
705
|
+
|
706
|
+
|
707
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
708
|
+
|
709
|
+
|
710
|
+
|
711
|
+
</li>
|
712
|
+
|
713
|
+
</ul>
|
714
|
+
|
715
|
+
</div><table class="source_code">
|
716
|
+
<tr>
|
717
|
+
<td>
|
718
|
+
<pre class="lines">
|
719
|
+
|
720
|
+
|
721
|
+
57
|
722
|
+
58
|
723
|
+
59
|
724
|
+
60
|
725
|
+
61
|
726
|
+
62</pre>
|
727
|
+
</td>
|
728
|
+
<td>
|
729
|
+
<pre class="code"><span class="info file"># File 'lib/simple/service.rb', line 57</span>
|
730
|
+
|
731
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_service?'>service?</span><span class='lparen'>(</span><span class='id identifier rubyid_service'>service</span><span class='rparen'>)</span>
|
732
|
+
<span class='id identifier rubyid_verify_service!'>verify_service!</span> <span class='id identifier rubyid_service'>service</span>
|
733
|
+
<span class='kw'>true</span>
|
734
|
+
<span class='kw'>rescue</span> <span class='op'>::</span><span class='const'>ArgumentError</span>
|
735
|
+
<span class='kw'>false</span>
|
736
|
+
<span class='kw'>end</span></pre>
|
737
|
+
</td>
|
738
|
+
</tr>
|
739
|
+
</table>
|
740
|
+
</div>
|
741
|
+
|
742
|
+
<div class="method_details ">
|
743
|
+
<h3 class="signature " id="verify_service!-class_method">
|
744
|
+
|
745
|
+
.<strong>verify_service!</strong>(service) ⇒ <tt>Object</tt>
|
746
|
+
|
747
|
+
|
748
|
+
|
749
|
+
|
750
|
+
|
751
|
+
</h3><div class="docstring">
|
752
|
+
<div class="discussion">
|
753
|
+
|
754
|
+
<p>Raises an error if the passed in object is not a service</p>
|
755
|
+
|
756
|
+
|
757
|
+
</div>
|
758
|
+
</div>
|
759
|
+
<div class="tags">
|
760
|
+
|
761
|
+
<p class="tag_title">Raises:</p>
|
762
|
+
<ul class="raise">
|
763
|
+
|
764
|
+
<li>
|
765
|
+
|
766
|
+
|
767
|
+
<span class='type'>(<tt>::ArgumentError</tt>)</span>
|
768
|
+
|
769
|
+
|
770
|
+
|
771
|
+
</li>
|
772
|
+
|
773
|
+
</ul>
|
774
|
+
|
775
|
+
</div><table class="source_code">
|
776
|
+
<tr>
|
777
|
+
<td>
|
778
|
+
<pre class="lines">
|
779
|
+
|
780
|
+
|
781
|
+
65
|
782
|
+
66
|
783
|
+
67
|
784
|
+
68</pre>
|
785
|
+
</td>
|
786
|
+
<td>
|
787
|
+
<pre class="code"><span class="info file"># File 'lib/simple/service.rb', line 65</span>
|
788
|
+
|
789
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_verify_service!'>verify_service!</span><span class='lparen'>(</span><span class='id identifier rubyid_service'>service</span><span class='rparen'>)</span> <span class='comment'># @private
|
790
|
+
</span> <span class='id identifier rubyid_raise'>raise</span> <span class='op'>::</span><span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_service'>service</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_content'> must be a Simple::Service, but is not even a Module</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_service'>service</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Module</span><span class='rparen'>)</span>
|
791
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='op'>::</span><span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_service'>service</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_content'> must be a Simple::Service, did you 'include Simple::Service'</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_service'>service</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='kw'>self</span><span class='rparen'>)</span>
|
792
|
+
<span class='kw'>end</span></pre>
|
793
|
+
</td>
|
794
|
+
</tr>
|
795
|
+
</table>
|
796
|
+
</div>
|
797
|
+
|
798
|
+
<div class="method_details ">
|
799
|
+
<h3 class="signature " id="with_context-class_method">
|
800
|
+
|
801
|
+
.<strong>with_context</strong>(ctx = nil, &block) ⇒ <tt>Object</tt>
|
802
|
+
|
803
|
+
|
804
|
+
|
805
|
+
|
806
|
+
|
807
|
+
</h3><div class="docstring">
|
808
|
+
<div class="discussion">
|
809
|
+
|
810
|
+
<p>yields a block with a given context, and restores the previous context object afterwards.</p>
|
811
|
+
|
812
|
+
|
813
|
+
</div>
|
814
|
+
</div>
|
815
|
+
<div class="tags">
|
816
|
+
|
817
|
+
|
818
|
+
</div><table class="source_code">
|
819
|
+
<tr>
|
820
|
+
<td>
|
821
|
+
<pre class="lines">
|
822
|
+
|
823
|
+
|
824
|
+
9
|
825
|
+
10
|
826
|
+
11
|
827
|
+
12
|
828
|
+
13
|
829
|
+
14
|
830
|
+
15
|
831
|
+
16
|
832
|
+
17
|
833
|
+
18</pre>
|
834
|
+
</td>
|
835
|
+
<td>
|
836
|
+
<pre class="code"><span class="info file"># File 'lib/simple/service/context.rb', line 9</span>
|
837
|
+
|
838
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_with_context'>with_context</span><span class='lparen'>(</span><span class='id identifier rubyid_ctx'>ctx</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
839
|
+
<span class='id identifier rubyid_old_ctx'>old_ctx</span> <span class='op'>=</span> <span class='const'>Thread</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='lbracket'>[</span><span class='symbol'>:"Simple::Service.context"</span><span class='rbracket'>]</span>
|
840
|
+
<span class='id identifier rubyid_new_ctx'>new_ctx</span> <span class='op'>=</span> <span class='id identifier rubyid_old_ctx'>old_ctx</span> <span class='op'>?</span> <span class='id identifier rubyid_old_ctx'>old_ctx</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='id identifier rubyid_ctx'>ctx</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='const'><span class='object_link'><a href="Service/Context.html" title="Simple::Service::Context (class)">Context</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Service/Context.html#initialize-instance_method" title="Simple::Service::Context#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_ctx'>ctx</span><span class='rparen'>)</span>
|
841
|
+
|
842
|
+
<span class='const'>Thread</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='lbracket'>[</span><span class='symbol'>:"Simple::Service.context"</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_new_ctx'>new_ctx</span>
|
843
|
+
|
844
|
+
<span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span>
|
845
|
+
<span class='kw'>ensure</span>
|
846
|
+
<span class='const'>Thread</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='lbracket'>[</span><span class='symbol'>:"Simple::Service.context"</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_old_ctx'>old_ctx</span>
|
847
|
+
<span class='kw'>end</span></pre>
|
848
|
+
</td>
|
849
|
+
</tr>
|
850
|
+
</table>
|
851
|
+
</div>
|
852
|
+
|
853
|
+
</div>
|
854
|
+
|
855
|
+
</div>
|
856
|
+
|
857
|
+
<div id="footer">
|
858
|
+
Generated on Wed Dec 4 22:57:13 2019 by
|
859
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
860
|
+
0.9.20 (ruby-2.5.1).
|
861
|
+
</div>
|
862
|
+
|
863
|
+
</div>
|
864
|
+
</body>
|
865
|
+
</html>
|