kaicho 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +6 -6
- data/lib/kaicho.rb +68 -19
- data/lib/kaicho/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10295f3c7c5a763d97c7f2e611c1f63766a6250d937e1295881031fecda0d08e
|
4
|
+
data.tar.gz: bf5e3bd28fbd09324a6944cdb09035d5c83bdfae97a4abefac3715255b302527
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 275467c78b00d15d69d4b614e62080ac40bae1fe11b3513464856f7c06e9fa6a4c01f2e2c372fdc5893a24f39f7abe2bbbeb3633a881a9ea6bb869cd59a23b28
|
7
|
+
data.tar.gz: eb7a56313adcb19c7fe8faebb5590795231c188bb2e8e89cade8d3417467bc1ac1dd68cc1684f45e310e6396f7234b85a7885801ebabf2cf3763a456a2907df3
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kaicho (0.
|
4
|
+
kaicho (0.2.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -15,14 +15,14 @@ GEM
|
|
15
15
|
diff-lcs (1.3)
|
16
16
|
docile (1.3.1)
|
17
17
|
json (2.1.0)
|
18
|
-
rake (12.3.
|
18
|
+
rake (12.3.2)
|
19
19
|
rspec (3.8.0)
|
20
20
|
rspec-core (~> 3.8.0)
|
21
21
|
rspec-expectations (~> 3.8.0)
|
22
22
|
rspec-mocks (~> 3.8.0)
|
23
23
|
rspec-core (3.8.0)
|
24
24
|
rspec-support (~> 3.8.0)
|
25
|
-
rspec-expectations (3.8.
|
25
|
+
rspec-expectations (3.8.2)
|
26
26
|
diff-lcs (>= 1.2.0, < 2.0)
|
27
27
|
rspec-support (~> 3.8.0)
|
28
28
|
rspec-mocks (3.8.0)
|
@@ -34,10 +34,10 @@ GEM
|
|
34
34
|
json (>= 1.8, < 3)
|
35
35
|
simplecov-html (~> 0.10.0)
|
36
36
|
simplecov-html (0.10.2)
|
37
|
-
term-ansicolor (1.
|
37
|
+
term-ansicolor (1.7.0)
|
38
38
|
tins (~> 1.0)
|
39
39
|
thor (0.19.4)
|
40
|
-
tins (1.
|
40
|
+
tins (1.20.2)
|
41
41
|
|
42
42
|
PLATFORMS
|
43
43
|
ruby
|
@@ -50,4 +50,4 @@ DEPENDENCIES
|
|
50
50
|
rspec (~> 3.8, >= 3.8.0)
|
51
51
|
|
52
52
|
BUNDLED WITH
|
53
|
-
1.
|
53
|
+
1.17.1
|
data/lib/kaicho.rb
CHANGED
@@ -15,6 +15,35 @@ require 'kaicho/util'
|
|
15
15
|
#
|
16
16
|
# Note that all methods act on instances of Classes at the moment.
|
17
17
|
module Kaicho
|
18
|
+
# Called when Kaicho is `include`d
|
19
|
+
# if you use the provided class methods, be sure to call super in your
|
20
|
+
# initialize method, otherwise they will have no effect
|
21
|
+
def self.append_features(rcvr)
|
22
|
+
super
|
23
|
+
|
24
|
+
rcvr.instance_variable_set(:@class_resources, [])
|
25
|
+
rcvr.instance_variable_set(:@class_triggers, [])
|
26
|
+
|
27
|
+
# @see #def_resource
|
28
|
+
rcvr.define_singleton_method(:def_resource) do |*args, &block|
|
29
|
+
@class_resources << [args, block]
|
30
|
+
end
|
31
|
+
|
32
|
+
# @see #add_triggers
|
33
|
+
rcvr.define_singleton_method(:add_triggers) do |*triggers|
|
34
|
+
@triggers += triggers
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize
|
39
|
+
(self.class.instance_variable_get(:@class_resources))
|
40
|
+
.each { |args, block| def_resource(*args, &block) }
|
41
|
+
|
42
|
+
add_triggers(*(self.class.instance_variable_get(:@class_triggers)))
|
43
|
+
|
44
|
+
super
|
45
|
+
end
|
46
|
+
|
18
47
|
# adds trigger(s) which can be used to trigger updates of resources
|
19
48
|
# who have the trigger set
|
20
49
|
#
|
@@ -64,7 +93,7 @@ module Kaicho
|
|
64
93
|
end
|
65
94
|
|
66
95
|
define_singleton_method(dname) do
|
67
|
-
update_resource(dname) unless
|
96
|
+
update_resource(dname, rand) unless resource_defined?(dname)
|
68
97
|
read.call
|
69
98
|
end
|
70
99
|
|
@@ -90,7 +119,7 @@ module Kaicho
|
|
90
119
|
|
91
120
|
define_singleton_method(:"#{dname}=") do |v|
|
92
121
|
write.call(v)
|
93
|
-
update_dependants(dname)
|
122
|
+
update_dependants(dname, rand)
|
94
123
|
v
|
95
124
|
end
|
96
125
|
|
@@ -121,6 +150,7 @@ module Kaicho
|
|
121
150
|
# - +:write+, +:w+ - defines an {#attr_writer}
|
122
151
|
# - +:both+, +:rw+ - defines both, see {#attr_accessor}
|
123
152
|
# - +:none+ - don't generate any accessors
|
153
|
+
# @param [Symbol] accessors alias to accessor
|
124
154
|
# @param block a block that will be called, with no arguments, to update this
|
125
155
|
# resource
|
126
156
|
# @return [True] this method always returns true or raises an exception
|
@@ -128,15 +158,20 @@ module Kaicho
|
|
128
158
|
depends: {},
|
129
159
|
triggers: [],
|
130
160
|
overwrite: false,
|
131
|
-
share:
|
132
|
-
accessor:
|
161
|
+
share: nil,
|
162
|
+
accessor: :read,
|
163
|
+
accessors: nil,
|
133
164
|
&block)
|
134
165
|
@resources ||= {}
|
135
166
|
|
167
|
+
accessor = accessors unless accessors.nil?
|
168
|
+
|
136
169
|
Kaicho::Util.check_type(Symbol, dname)
|
137
170
|
Kaicho::Util.check_type(Hash, depends)
|
138
171
|
Kaicho::Util.check_type(Array, triggers)
|
139
172
|
|
173
|
+
block = nil unless block_given?
|
174
|
+
|
140
175
|
unless %i[read r write w both rw none].include?(accessor)
|
141
176
|
raise(ArgumentError, "invalid accessor: :#{accessor}")
|
142
177
|
end
|
@@ -208,23 +243,23 @@ module Kaicho
|
|
208
243
|
end
|
209
244
|
|
210
245
|
return if @resources[dname][:udid] == udid
|
211
|
-
|
212
246
|
udid ||= rand
|
247
|
+
@resources[dname][:udid] = udid
|
213
248
|
|
214
249
|
return unless update_depends(dname, udid)
|
215
250
|
|
216
|
-
|
251
|
+
unless @resources[dname][:proc].nil?
|
252
|
+
result = self.instance_exec(&@resources[dname][:proc])
|
217
253
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
254
|
+
if @resources[dname][:share].nil?
|
255
|
+
instance_variable_set(@resources[dname][:varname], result)
|
256
|
+
else
|
257
|
+
@resources[dname][:share].class_variable_set(
|
258
|
+
@resources[dname][:varname], result
|
259
|
+
)
|
260
|
+
end
|
224
261
|
end
|
225
262
|
|
226
|
-
@resources[dname][:udid] = udid
|
227
|
-
|
228
263
|
update_dependants(dname, udid)
|
229
264
|
|
230
265
|
true
|
@@ -237,7 +272,7 @@ module Kaicho
|
|
237
272
|
# @param dname the name of the resource
|
238
273
|
# @param udid the update-id of this call, this should be left +nil+. It is
|
239
274
|
# internally to avoid infinite loops during update cascades.
|
240
|
-
# @return [
|
275
|
+
# @return [bool] returns false if the resource could not be found, else return true
|
241
276
|
def update_depends(dname, udid = nil)
|
242
277
|
udid ||= rand
|
243
278
|
@resources[dname][:depends].each do |d, o|
|
@@ -265,10 +300,9 @@ module Kaicho
|
|
265
300
|
# @return [True] this method always returns true or raises an exception
|
266
301
|
def update_dependants(dname, udid = nil)
|
267
302
|
udid ||= rand
|
268
|
-
|
303
|
+
@resources.select do |_, v|
|
269
304
|
v[:depends].include?(dname) && v[:udid] != udid
|
270
|
-
end
|
271
|
-
dependants.each { |d, _| update_resource(d, udid) }
|
305
|
+
end.each { |d, _| update_resource(d, udid) }
|
272
306
|
|
273
307
|
true
|
274
308
|
end
|
@@ -295,8 +329,23 @@ module Kaicho
|
|
295
329
|
# @return [True] this method always returns true or raises an exception
|
296
330
|
def update_all_resources
|
297
331
|
udid = rand
|
298
|
-
|
332
|
+
|
333
|
+
resource_roots.each { |d| update_resource(d, udid) }
|
299
334
|
|
300
335
|
true
|
301
336
|
end
|
337
|
+
|
338
|
+
# Determine the root resources of the current object
|
339
|
+
#
|
340
|
+
# A resource is a root resource if it either does not depend on anything or
|
341
|
+
# all of its dependencies have the +:fail+ action (i.e. they are not managed
|
342
|
+
# by kaicho)
|
343
|
+
#
|
344
|
+
# @return [Array] an array of Symbol where each element is the name of a
|
345
|
+
# resource root
|
346
|
+
def resource_roots
|
347
|
+
@resources.select do |a, attr|
|
348
|
+
attr[:depends].empty? || attr[:depends].all? { |_,a| a == :fail }
|
349
|
+
end.map { |a, _| a }
|
350
|
+
end
|
302
351
|
end
|
data/lib/kaicho/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kaicho
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stone Tickle
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|