simple-service 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/simple/service.rb +0 -1
- data/lib/simple/service/action.rb +12 -3
- data/lib/simple/service/action/indie_hash.rb +37 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5300b67f8c93b974d4ae19f285aa80915b195f8c5483c340b1716ecf2b41f969
|
4
|
+
data.tar.gz: 4272fc5ea6add6f0bb774c7faee8d2abe00ad0f1bda1056b80cc3a57a9ab6df5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83233c349d6a144183f0ca2a18993712a4902dcc65934a63dcc7cfed370ffc1ddcdfa7754a1ffff85f11c8875007de7843f8c5d7fd8d6f7eb799dd14c1e3b373
|
7
|
+
data.tar.gz: '0268ef5da51bcca27e9a3a1766f9ede7d67a8213cf52b97206d000836012cd7c3220511098dad734c316fa3a068f3e853301ffaf8b8dac73712b3f3757dd674b'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/simple/service.rb
CHANGED
@@ -70,7 +70,6 @@ module Simple::Service
|
|
70
70
|
#
|
71
71
|
# You cannot call this method if the context is not set.
|
72
72
|
def self.invoke2(service, name, args: {}, flags: {})
|
73
|
-
args.each { |key, _| expect! key => Symbol }
|
74
73
|
raise ContextMissingError, "Need to set context before calling ::Simple::Service.invoke" unless context
|
75
74
|
|
76
75
|
action(service, name).invoke2(args: args, flags: flags)
|
@@ -5,6 +5,7 @@ end
|
|
5
5
|
|
6
6
|
require_relative "./action/comment"
|
7
7
|
require_relative "./action/parameter"
|
8
|
+
require_relative "./action/indie_hash"
|
8
9
|
|
9
10
|
module Simple::Service
|
10
11
|
# rubocop:disable Metrics/AbcSize
|
@@ -89,6 +90,12 @@ module Simple::Service
|
|
89
90
|
#
|
90
91
|
# You cannot call this method if the context is not set.
|
91
92
|
def invoke2(args:, flags:)
|
93
|
+
# args and flags are being stringified. This is necessary to not allow any
|
94
|
+
# unchecked input to DOS this process by just providing always changing
|
95
|
+
# key values.
|
96
|
+
args = IndieHash.new(args)
|
97
|
+
flags = IndieHash.new(flags)
|
98
|
+
|
92
99
|
verify_required_args!(args, flags)
|
93
100
|
|
94
101
|
positionals = build_positional_arguments(args, flags)
|
@@ -110,7 +117,7 @@ module Simple::Service
|
|
110
117
|
|
111
118
|
# returns an error if the keywords hash does not define all required keyword arguments.
|
112
119
|
def verify_required_args!(args, flags) # :nodoc:
|
113
|
-
@required_names ||= parameters.select(&:required?).map(&:name)
|
120
|
+
@required_names ||= parameters.select(&:required?).map(&:name).map(&:to_s)
|
114
121
|
|
115
122
|
missing_parameters = @required_names - args.keys - flags.keys
|
116
123
|
return if missing_parameters.empty?
|
@@ -121,12 +128,14 @@ module Simple::Service
|
|
121
128
|
# Enumerating all parameters it puts all named parameters into a Hash
|
122
129
|
# of keyword arguments.
|
123
130
|
def build_keyword_arguments(args)
|
124
|
-
@keyword_names ||= parameters.select(&:keyword?).map(&:name)
|
131
|
+
@keyword_names ||= parameters.select(&:keyword?).map(&:name).map(&:to_s)
|
125
132
|
|
126
133
|
keys = @keyword_names & args.keys
|
127
134
|
values = args.fetch_values(*keys)
|
128
135
|
|
129
|
-
|
136
|
+
# Note that +keys+ now only contains names of keyword arguments that actually exist.
|
137
|
+
# This is therefore not a way to DOS this process.
|
138
|
+
Hash[keys.map(&:to_sym).zip(values)]
|
130
139
|
end
|
131
140
|
|
132
141
|
def variadic_parameter
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Simple::Service::Action
|
2
|
+
# The IndieHash class defines as much of the Hash interface as necessary for simple-service
|
3
|
+
# to successfully run.
|
4
|
+
class IndieHash
|
5
|
+
def initialize(hsh)
|
6
|
+
@hsh = hsh.each_with_object({}) { |(k, v), h| h[k.to_s] = v }
|
7
|
+
end
|
8
|
+
|
9
|
+
def keys
|
10
|
+
@hsh.keys
|
11
|
+
end
|
12
|
+
|
13
|
+
def fetch_values(*keys)
|
14
|
+
keys = keys.map(&:to_s)
|
15
|
+
@hsh.fetch_values(*keys)
|
16
|
+
end
|
17
|
+
|
18
|
+
def key?(sym)
|
19
|
+
@hsh.key?(sym.to_s)
|
20
|
+
end
|
21
|
+
|
22
|
+
def [](sym)
|
23
|
+
@hsh[sym.to_s]
|
24
|
+
end
|
25
|
+
|
26
|
+
def merge(other_hsh)
|
27
|
+
@hsh = @hsh.merge(other_hsh.send(:__hsh__))
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def __hsh__
|
34
|
+
@hsh
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- radiospiel
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- lib/simple/service.rb
|
47
47
|
- lib/simple/service/action.rb
|
48
48
|
- lib/simple/service/action/comment.rb
|
49
|
+
- lib/simple/service/action/indie_hash.rb
|
49
50
|
- lib/simple/service/action/method_reflection.rb
|
50
51
|
- lib/simple/service/action/parameter.rb
|
51
52
|
- lib/simple/service/context.rb
|