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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7921a94a0cb4244efa536f350ec568d21f9d5a5b09e141c459a7e0ad59eb4076
|
4
|
+
data.tar.gz: 2c07601a1334a830bd2ff4b406563d73f816d9cbdc3ced6b788237d15cfce7ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97c672710c6317d3eda455b1c1eda485ebc80aed55ce5e3ec6d1af3b08e372247cfdcfbb9e56aabab6e06456bd45f0a5b9b9945e5d980cf7e4886e59fceb735b
|
7
|
+
data.tar.gz: e0733c90d2a99af1c4c88ad4053b4130f7d73fc8d4e2d80e632196ca19dfe4ec5d7480710f789595c6644089410116e392bc48eadba14261347f31e20b996024
|
data/.gitignore
CHANGED
data/Makefile
CHANGED
@@ -3,14 +3,7 @@
|
|
3
3
|
test:
|
4
4
|
rspec
|
5
5
|
|
6
|
-
.PHONY: doc
|
7
|
-
doc:
|
8
|
-
|
9
|
-
doc
|
10
|
-
rm -rf doc/rdoc
|
11
|
-
rdoc -o doc/rdoc README.md \
|
12
|
-
lib/simple/service.rb \
|
13
|
-
lib/simple/service/action.rb \
|
14
|
-
lib/simple/service/context.rb \
|
15
|
-
lib/simple/service/errors.rb \
|
16
|
-
lib/simple/service/version.rb
|
6
|
+
.PHONY: doc
|
7
|
+
doc:
|
8
|
+
rm -rf doc/*
|
9
|
+
yard doc -o doc
|
data/README.md
CHANGED
@@ -1,3 +1,68 @@
|
|
1
|
-
# simple-service –
|
1
|
+
# simple-service – at your service!
|
2
2
|
|
3
|
-
|
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/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
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 Tue Dec 3 13:46:26 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,863 @@
|
|
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>The <strong>Simple::Service</strong> interface</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. [TODO] why a Hash?</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><li>
|
118
|
+
<p><em>Invoke a service:</em> run <code>Simple::Service.invoke</code> or <code>Simple::Service.invoke2</code>. You must set a context first. </p>
|
119
|
+
|
120
|
+
<pre class="code ruby"><code class="ruby">Simple::Service.with_context do
|
121
|
+
Simple::Service.invoke(GodMode, :build_universe, "TestWorld", c: 1e9)
|
122
|
+
end
|
123
|
+
=> 42
|
124
|
+
</code></pre>
|
125
|
+
</li></ol>
|
126
|
+
|
127
|
+
|
128
|
+
</div>
|
129
|
+
</div>
|
130
|
+
<div class="tags">
|
131
|
+
|
132
|
+
|
133
|
+
</div><h2>Defined Under Namespace</h2>
|
134
|
+
<p class="children">
|
135
|
+
|
136
|
+
|
137
|
+
<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>
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
<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>
|
142
|
+
|
143
|
+
|
144
|
+
</p>
|
145
|
+
|
146
|
+
|
147
|
+
<h2>
|
148
|
+
Constant Summary
|
149
|
+
<small><a href="#" class="constants_summary_toggle">collapse</a></small>
|
150
|
+
</h2>
|
151
|
+
|
152
|
+
<dl class="constants">
|
153
|
+
|
154
|
+
<dt id="VERSION-constant" class="">VERSION =
|
155
|
+
|
156
|
+
</dt>
|
157
|
+
<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>
|
158
|
+
|
159
|
+
</dl>
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
<h2>
|
170
|
+
Class Method Summary
|
171
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
172
|
+
</h2>
|
173
|
+
|
174
|
+
<ul class="summary">
|
175
|
+
|
176
|
+
<li class="public ">
|
177
|
+
<span class="summary_signature">
|
178
|
+
|
179
|
+
<a href="#action-class_method" title="action (class method)">.<strong>action</strong>(service, name) ⇒ Object </a>
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
</span>
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
<span class="summary_desc"><div class='inline'>
|
194
|
+
<p>returns the action with the given name.</p>
|
195
|
+
</div></span>
|
196
|
+
|
197
|
+
</li>
|
198
|
+
|
199
|
+
|
200
|
+
<li class="public ">
|
201
|
+
<span class="summary_signature">
|
202
|
+
|
203
|
+
<a href="#actions-class_method" title="actions (class method)">.<strong>actions</strong>(service) ⇒ Object </a>
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
</span>
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
<span class="summary_desc"><div class='inline'>
|
218
|
+
<p>returns a Hash with all actions in the <code>service</code> module.</p>
|
219
|
+
</div></span>
|
220
|
+
|
221
|
+
</li>
|
222
|
+
|
223
|
+
|
224
|
+
<li class="public ">
|
225
|
+
<span class="summary_signature">
|
226
|
+
|
227
|
+
<a href="#context-class_method" title="context (class method)">.<strong>context</strong> ⇒ Object </a>
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
</span>
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
<span class="summary_desc"><div class='inline'>
|
242
|
+
<p>Returns the current context.</p>
|
243
|
+
</div></span>
|
244
|
+
|
245
|
+
</li>
|
246
|
+
|
247
|
+
|
248
|
+
<li class="public ">
|
249
|
+
<span class="summary_signature">
|
250
|
+
|
251
|
+
<a href="#included-class_method" title="included (class method)">.<strong>included</strong>(klass) ⇒ Object </a>
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
</span>
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
266
|
+
|
267
|
+
</li>
|
268
|
+
|
269
|
+
|
270
|
+
<li class="public ">
|
271
|
+
<span class="summary_signature">
|
272
|
+
|
273
|
+
<a href="#invoke-class_method" title="invoke (class method)">.<strong>invoke</strong>(service, name, *args, **named_args) ⇒ Object </a>
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
</span>
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
<span class="summary_desc"><div class='inline'>
|
288
|
+
<p>invokes an action with a given <code>name</code> in a service with <code>arguments</code> and <code>params</code>.</p>
|
289
|
+
</div></span>
|
290
|
+
|
291
|
+
</li>
|
292
|
+
|
293
|
+
|
294
|
+
<li class="public ">
|
295
|
+
<span class="summary_signature">
|
296
|
+
|
297
|
+
<a href="#invoke2-class_method" title="invoke2 (class method)">.<strong>invoke2</strong>(service, name, args: {}, flags: {}) ⇒ Object </a>
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
</span>
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
<span class="summary_desc"><div class='inline'>
|
312
|
+
<p>invokes an action with a given <code>name</code> in a service with a Hash of arguments.</p>
|
313
|
+
</div></span>
|
314
|
+
|
315
|
+
</li>
|
316
|
+
|
317
|
+
|
318
|
+
<li class="public ">
|
319
|
+
<span class="summary_signature">
|
320
|
+
|
321
|
+
<a href="#service%3F-class_method" title="service? (class method)">.<strong>service?</strong>(service) ⇒ Boolean </a>
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
</span>
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
<span class="summary_desc"><div class='inline'>
|
336
|
+
<p>returns true if the passed in object is a service module.</p>
|
337
|
+
</div></span>
|
338
|
+
|
339
|
+
</li>
|
340
|
+
|
341
|
+
|
342
|
+
<li class="public ">
|
343
|
+
<span class="summary_signature">
|
344
|
+
|
345
|
+
<a href="#verify_service!-class_method" title="verify_service! (class method)">.<strong>verify_service!</strong>(service) ⇒ Object </a>
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
</span>
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
360
|
+
|
361
|
+
</li>
|
362
|
+
|
363
|
+
|
364
|
+
<li class="public ">
|
365
|
+
<span class="summary_signature">
|
366
|
+
|
367
|
+
<a href="#with_context-class_method" title="with_context (class method)">.<strong>with_context</strong>(ctx = nil, &block) ⇒ Object </a>
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
</span>
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
<span class="summary_desc"><div class='inline'>
|
382
|
+
<p>yields a block with a given context, and restores the previous context object afterwards.</p>
|
383
|
+
</div></span>
|
384
|
+
|
385
|
+
</li>
|
386
|
+
|
387
|
+
|
388
|
+
</ul>
|
389
|
+
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
<div id="class_method_details" class="method_details_list">
|
394
|
+
<h2>Class Method Details</h2>
|
395
|
+
|
396
|
+
|
397
|
+
<div class="method_details first">
|
398
|
+
<h3 class="signature first" id="action-class_method">
|
399
|
+
|
400
|
+
.<strong>action</strong>(service, name) ⇒ <tt>Object</tt>
|
401
|
+
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
|
406
|
+
</h3><div class="docstring">
|
407
|
+
<div class="discussion">
|
408
|
+
|
409
|
+
<p>returns the action with the given name.</p>
|
410
|
+
|
411
|
+
|
412
|
+
</div>
|
413
|
+
</div>
|
414
|
+
<div class="tags">
|
415
|
+
|
416
|
+
|
417
|
+
</div><table class="source_code">
|
418
|
+
<tr>
|
419
|
+
<td>
|
420
|
+
<pre class="lines">
|
421
|
+
|
422
|
+
|
423
|
+
69
|
424
|
+
70
|
425
|
+
71
|
426
|
+
72
|
427
|
+
73
|
428
|
+
74</pre>
|
429
|
+
</td>
|
430
|
+
<td>
|
431
|
+
<pre class="code"><span class="info file"># File 'lib/simple/service.rb', line 69</span>
|
432
|
+
|
433
|
+
<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>
|
434
|
+
<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>
|
435
|
+
<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>
|
436
|
+
<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>
|
437
|
+
<span class='kw'>end</span>
|
438
|
+
<span class='kw'>end</span></pre>
|
439
|
+
</td>
|
440
|
+
</tr>
|
441
|
+
</table>
|
442
|
+
</div>
|
443
|
+
|
444
|
+
<div class="method_details ">
|
445
|
+
<h3 class="signature " id="actions-class_method">
|
446
|
+
|
447
|
+
.<strong>actions</strong>(service) ⇒ <tt>Object</tt>
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
</h3><div class="docstring">
|
454
|
+
<div class="discussion">
|
455
|
+
|
456
|
+
<p>returns a Hash with all actions in the <code>service</code> module</p>
|
457
|
+
|
458
|
+
|
459
|
+
</div>
|
460
|
+
</div>
|
461
|
+
<div class="tags">
|
462
|
+
|
463
|
+
|
464
|
+
</div><table class="source_code">
|
465
|
+
<tr>
|
466
|
+
<td>
|
467
|
+
<pre class="lines">
|
468
|
+
|
469
|
+
|
470
|
+
62
|
471
|
+
63
|
472
|
+
64
|
473
|
+
65
|
474
|
+
66</pre>
|
475
|
+
</td>
|
476
|
+
<td>
|
477
|
+
<pre class="code"><span class="info file"># File 'lib/simple/service.rb', line 62</span>
|
478
|
+
|
479
|
+
<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>
|
480
|
+
<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>
|
481
|
+
|
482
|
+
<span class='id identifier rubyid_service'>service</span><span class='period'>.</span><span class='id identifier rubyid___simple_service_actions__'>__simple_service_actions__</span>
|
483
|
+
<span class='kw'>end</span></pre>
|
484
|
+
</td>
|
485
|
+
</tr>
|
486
|
+
</table>
|
487
|
+
</div>
|
488
|
+
|
489
|
+
<div class="method_details ">
|
490
|
+
<h3 class="signature " id="context-class_method">
|
491
|
+
|
492
|
+
.<strong>context</strong> ⇒ <tt>Object</tt>
|
493
|
+
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
|
498
|
+
</h3><div class="docstring">
|
499
|
+
<div class="discussion">
|
500
|
+
|
501
|
+
<p>Returns the current context.</p>
|
502
|
+
|
503
|
+
|
504
|
+
</div>
|
505
|
+
</div>
|
506
|
+
<div class="tags">
|
507
|
+
|
508
|
+
|
509
|
+
</div><table class="source_code">
|
510
|
+
<tr>
|
511
|
+
<td>
|
512
|
+
<pre class="lines">
|
513
|
+
|
514
|
+
|
515
|
+
3
|
516
|
+
4
|
517
|
+
5</pre>
|
518
|
+
</td>
|
519
|
+
<td>
|
520
|
+
<pre class="code"><span class="info file"># File 'lib/simple/service/context.rb', line 3</span>
|
521
|
+
|
522
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_context'>context</span>
|
523
|
+
<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>
|
524
|
+
<span class='kw'>end</span></pre>
|
525
|
+
</td>
|
526
|
+
</tr>
|
527
|
+
</table>
|
528
|
+
</div>
|
529
|
+
|
530
|
+
<div class="method_details ">
|
531
|
+
<h3 class="signature " id="included-class_method">
|
532
|
+
|
533
|
+
.<strong>included</strong>(klass) ⇒ <tt>Object</tt>
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
|
538
|
+
|
539
|
+
</h3><table class="source_code">
|
540
|
+
<tr>
|
541
|
+
<td>
|
542
|
+
<pre class="lines">
|
543
|
+
|
544
|
+
|
545
|
+
47
|
546
|
+
48
|
547
|
+
49</pre>
|
548
|
+
</td>
|
549
|
+
<td>
|
550
|
+
<pre class="code"><span class="info file"># File 'lib/simple/service.rb', line 47</span>
|
551
|
+
|
552
|
+
<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
|
553
|
+
</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>
|
554
|
+
<span class='kw'>end</span></pre>
|
555
|
+
</td>
|
556
|
+
</tr>
|
557
|
+
</table>
|
558
|
+
</div>
|
559
|
+
|
560
|
+
<div class="method_details ">
|
561
|
+
<h3 class="signature " id="invoke-class_method">
|
562
|
+
|
563
|
+
.<strong>invoke</strong>(service, name, *args, **named_args) ⇒ <tt>Object</tt>
|
564
|
+
|
565
|
+
|
566
|
+
|
567
|
+
|
568
|
+
|
569
|
+
</h3><div class="docstring">
|
570
|
+
<div class="discussion">
|
571
|
+
|
572
|
+
<p>invokes an action with a given <code>name</code> in a service with <code>arguments</code> and <code>params</code>.</p>
|
573
|
+
|
574
|
+
<p>You cannot call this method if the context is not set.</p>
|
575
|
+
|
576
|
+
<p>When calling #invoke using positional arguments they will be matched against positional arguments of the invoked method - but they will not be matched against named arguments.</p>
|
577
|
+
|
578
|
+
<p>When there are not enough positional arguments to match the number of required positional arguments of the method we raise an ArgumentError.</p>
|
579
|
+
|
580
|
+
<p>When there are more positional arguments provided than the number accepted by the method we raise an ArgumentError.</p>
|
581
|
+
|
582
|
+
<p>Entries in the named_args Hash that are not defined in the action itself are ignored.</p>
|
583
|
+
|
584
|
+
|
585
|
+
</div>
|
586
|
+
</div>
|
587
|
+
<div class="tags">
|
588
|
+
|
589
|
+
<p class="tag_title">Raises:</p>
|
590
|
+
<ul class="raise">
|
591
|
+
|
592
|
+
<li>
|
593
|
+
|
594
|
+
|
595
|
+
<span class='type'>(<tt><span class='object_link'><a href="Service/ContextMissingError.html" title="Simple::Service::ContextMissingError (class)">ContextMissingError</a></span></tt>)</span>
|
596
|
+
|
597
|
+
|
598
|
+
|
599
|
+
</li>
|
600
|
+
|
601
|
+
</ul>
|
602
|
+
|
603
|
+
</div><table class="source_code">
|
604
|
+
<tr>
|
605
|
+
<td>
|
606
|
+
<pre class="lines">
|
607
|
+
|
608
|
+
|
609
|
+
91
|
610
|
+
92
|
611
|
+
93
|
612
|
+
94
|
613
|
+
95</pre>
|
614
|
+
</td>
|
615
|
+
<td>
|
616
|
+
<pre class="code"><span class="info file"># File 'lib/simple/service.rb', line 91</span>
|
617
|
+
|
618
|
+
<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='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_named_args'>named_args</span><span class='rparen'>)</span>
|
619
|
+
<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.invoke</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_context'>context</span>
|
620
|
+
|
621
|
+
<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='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_named_args'>named_args</span><span class='rparen'>)</span>
|
622
|
+
<span class='kw'>end</span></pre>
|
623
|
+
</td>
|
624
|
+
</tr>
|
625
|
+
</table>
|
626
|
+
</div>
|
627
|
+
|
628
|
+
<div class="method_details ">
|
629
|
+
<h3 class="signature " id="invoke2-class_method">
|
630
|
+
|
631
|
+
.<strong>invoke2</strong>(service, name, args: {}, flags: {}) ⇒ <tt>Object</tt>
|
632
|
+
|
633
|
+
|
634
|
+
|
635
|
+
|
636
|
+
|
637
|
+
</h3><div class="docstring">
|
638
|
+
<div class="discussion">
|
639
|
+
|
640
|
+
<p>invokes an action with a given <code>name</code> in a service with a Hash of arguments.</p>
|
641
|
+
|
642
|
+
<p>You cannot call this method if the context is not set.</p>
|
643
|
+
|
644
|
+
|
645
|
+
</div>
|
646
|
+
</div>
|
647
|
+
<div class="tags">
|
648
|
+
|
649
|
+
<p class="tag_title">Raises:</p>
|
650
|
+
<ul class="raise">
|
651
|
+
|
652
|
+
<li>
|
653
|
+
|
654
|
+
|
655
|
+
<span class='type'>(<tt><span class='object_link'><a href="Service/ContextMissingError.html" title="Simple::Service::ContextMissingError (class)">ContextMissingError</a></span></tt>)</span>
|
656
|
+
|
657
|
+
|
658
|
+
|
659
|
+
</li>
|
660
|
+
|
661
|
+
</ul>
|
662
|
+
|
663
|
+
</div><table class="source_code">
|
664
|
+
<tr>
|
665
|
+
<td>
|
666
|
+
<pre class="lines">
|
667
|
+
|
668
|
+
|
669
|
+
100
|
670
|
+
101
|
671
|
+
102
|
672
|
+
103
|
673
|
+
104</pre>
|
674
|
+
</td>
|
675
|
+
<td>
|
676
|
+
<pre class="code"><span class="info file"># File 'lib/simple/service.rb', line 100</span>
|
677
|
+
|
678
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_invoke2'>invoke2</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>
|
679
|
+
<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.invoke</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_context'>context</span>
|
680
|
+
|
681
|
+
<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_invoke2'>invoke2</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>
|
682
|
+
<span class='kw'>end</span></pre>
|
683
|
+
</td>
|
684
|
+
</tr>
|
685
|
+
</table>
|
686
|
+
</div>
|
687
|
+
|
688
|
+
<div class="method_details ">
|
689
|
+
<h3 class="signature " id="service?-class_method">
|
690
|
+
|
691
|
+
.<strong>service?</strong>(service) ⇒ <tt>Boolean</tt>
|
692
|
+
|
693
|
+
|
694
|
+
|
695
|
+
|
696
|
+
|
697
|
+
</h3><div class="docstring">
|
698
|
+
<div class="discussion">
|
699
|
+
|
700
|
+
<p>returns true if the passed in object is a service module.</p>
|
701
|
+
|
702
|
+
|
703
|
+
</div>
|
704
|
+
</div>
|
705
|
+
<div class="tags">
|
706
|
+
|
707
|
+
<p class="tag_title">Returns:</p>
|
708
|
+
<ul class="return">
|
709
|
+
|
710
|
+
<li>
|
711
|
+
|
712
|
+
|
713
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
714
|
+
|
715
|
+
|
716
|
+
|
717
|
+
</li>
|
718
|
+
|
719
|
+
</ul>
|
720
|
+
|
721
|
+
</div><table class="source_code">
|
722
|
+
<tr>
|
723
|
+
<td>
|
724
|
+
<pre class="lines">
|
725
|
+
|
726
|
+
|
727
|
+
52
|
728
|
+
53
|
729
|
+
54</pre>
|
730
|
+
</td>
|
731
|
+
<td>
|
732
|
+
<pre class="code"><span class="info file"># File 'lib/simple/service.rb', line 52</span>
|
733
|
+
|
734
|
+
<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>
|
735
|
+
<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> <span class='op'>&&</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>
|
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
|
+
|
755
|
+
</div>
|
756
|
+
</div>
|
757
|
+
<div class="tags">
|
758
|
+
|
759
|
+
<p class="tag_title">Raises:</p>
|
760
|
+
<ul class="raise">
|
761
|
+
|
762
|
+
<li>
|
763
|
+
|
764
|
+
|
765
|
+
<span class='type'>(<tt>::ArgumentError</tt>)</span>
|
766
|
+
|
767
|
+
|
768
|
+
|
769
|
+
</li>
|
770
|
+
|
771
|
+
</ul>
|
772
|
+
|
773
|
+
</div><table class="source_code">
|
774
|
+
<tr>
|
775
|
+
<td>
|
776
|
+
<pre class="lines">
|
777
|
+
|
778
|
+
|
779
|
+
56
|
780
|
+
57
|
781
|
+
58
|
782
|
+
59</pre>
|
783
|
+
</td>
|
784
|
+
<td>
|
785
|
+
<pre class="code"><span class="info file"># File 'lib/simple/service.rb', line 56</span>
|
786
|
+
|
787
|
+
<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
|
788
|
+
</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>
|
789
|
+
<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='lparen'>(</span><span class='id identifier rubyid_service'>service</span><span class='rparen'>)</span>
|
790
|
+
<span class='kw'>end</span></pre>
|
791
|
+
</td>
|
792
|
+
</tr>
|
793
|
+
</table>
|
794
|
+
</div>
|
795
|
+
|
796
|
+
<div class="method_details ">
|
797
|
+
<h3 class="signature " id="with_context-class_method">
|
798
|
+
|
799
|
+
.<strong>with_context</strong>(ctx = nil, &block) ⇒ <tt>Object</tt>
|
800
|
+
|
801
|
+
|
802
|
+
|
803
|
+
|
804
|
+
|
805
|
+
</h3><div class="docstring">
|
806
|
+
<div class="discussion">
|
807
|
+
|
808
|
+
<p>yields a block with a given context, and restores the previous context object afterwards.</p>
|
809
|
+
|
810
|
+
|
811
|
+
</div>
|
812
|
+
</div>
|
813
|
+
<div class="tags">
|
814
|
+
|
815
|
+
|
816
|
+
</div><table class="source_code">
|
817
|
+
<tr>
|
818
|
+
<td>
|
819
|
+
<pre class="lines">
|
820
|
+
|
821
|
+
|
822
|
+
9
|
823
|
+
10
|
824
|
+
11
|
825
|
+
12
|
826
|
+
13
|
827
|
+
14
|
828
|
+
15
|
829
|
+
16
|
830
|
+
17
|
831
|
+
18</pre>
|
832
|
+
</td>
|
833
|
+
<td>
|
834
|
+
<pre class="code"><span class="info file"># File 'lib/simple/service/context.rb', line 9</span>
|
835
|
+
|
836
|
+
<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>
|
837
|
+
<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>
|
838
|
+
<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>
|
839
|
+
|
840
|
+
<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>
|
841
|
+
|
842
|
+
<span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span>
|
843
|
+
<span class='kw'>ensure</span>
|
844
|
+
<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>
|
845
|
+
<span class='kw'>end</span></pre>
|
846
|
+
</td>
|
847
|
+
</tr>
|
848
|
+
</table>
|
849
|
+
</div>
|
850
|
+
|
851
|
+
</div>
|
852
|
+
|
853
|
+
</div>
|
854
|
+
|
855
|
+
<div id="footer">
|
856
|
+
Generated on Tue Dec 3 13:46:26 2019 by
|
857
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
858
|
+
0.9.20 (ruby-2.5.1).
|
859
|
+
</div>
|
860
|
+
|
861
|
+
</div>
|
862
|
+
</body>
|
863
|
+
</html>
|