kaicho 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -2
- data/Gemfile.lock +53 -0
- data/README.md +4 -0
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/bin/setup +2 -0
- data/kaicho.gemspec +19 -16
- data/lib/kaicho.rb +187 -115
- data/lib/kaicho/util.rb +24 -0
- data/lib/kaicho/version.rb +4 -1
- metadata +46 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b149a80108fa8af5935e0f99b59b90b2f969b4d386b14178b6eb90db506e5b4
|
4
|
+
data.tar.gz: 71a2d0c27a52c307b5593f69cb7a3922a3c9610a9772ba4ff5e21cba7c2eb3e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b0880aefc00222a7111195111ddf4924f5010ec5ca406c5420d399848d9e89a4f6cb2dab42b3296304423c567c8946cea28dafa3f8766709b7ac9a35823536e
|
7
|
+
data.tar.gz: 3342fc356fc06c54720d66ae236de47e77e2a300d919a97940c881c51ec72400650f42591f2ab84a7484024c8d6aff5a9a1ffecbc715dce998d316e9f2c0e84b
|
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
6
|
|
5
7
|
# Specify your gem's dependencies in kaicho.gemspec
|
6
8
|
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
kaicho (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coveralls (0.8.22)
|
10
|
+
json (>= 1.8, < 3)
|
11
|
+
simplecov (~> 0.16.1)
|
12
|
+
term-ansicolor (~> 1.3)
|
13
|
+
thor (~> 0.19.4)
|
14
|
+
tins (~> 1.6)
|
15
|
+
diff-lcs (1.3)
|
16
|
+
docile (1.3.1)
|
17
|
+
json (2.1.0)
|
18
|
+
rake (12.3.1)
|
19
|
+
rspec (3.8.0)
|
20
|
+
rspec-core (~> 3.8.0)
|
21
|
+
rspec-expectations (~> 3.8.0)
|
22
|
+
rspec-mocks (~> 3.8.0)
|
23
|
+
rspec-core (3.8.0)
|
24
|
+
rspec-support (~> 3.8.0)
|
25
|
+
rspec-expectations (3.8.1)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.8.0)
|
28
|
+
rspec-mocks (3.8.0)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.8.0)
|
31
|
+
rspec-support (3.8.0)
|
32
|
+
simplecov (0.16.1)
|
33
|
+
docile (~> 1.1)
|
34
|
+
json (>= 1.8, < 3)
|
35
|
+
simplecov-html (~> 0.10.0)
|
36
|
+
simplecov-html (0.10.2)
|
37
|
+
term-ansicolor (1.6.0)
|
38
|
+
tins (~> 1.0)
|
39
|
+
thor (0.19.4)
|
40
|
+
tins (1.16.3)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
bundler (~> 1.16, >= 1.16.5)
|
47
|
+
coveralls (~> 0.8, >= 0.8.22)
|
48
|
+
kaicho!
|
49
|
+
rake (~> 12.3, >= 12.3.1)
|
50
|
+
rspec (~> 3.8, >= 3.8.0)
|
51
|
+
|
52
|
+
BUNDLED WITH
|
53
|
+
1.16.5
|
data/README.md
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
# Kaicho
|
2
|
+
[![Build Status](https://travis-ci.org/annacrombie/kaicho.svg?branch=master)](https://travis-ci.org/annacrombie/kaicho)
|
3
|
+
[![Coverage Status](https://coveralls.io/repos/github/annacrombie/kaicho/badge.svg?branch=master)](https://coveralls.io/github/annacrombie/kaicho?branch=master)
|
4
|
+
[![Inline docs](http://inch-ci.org/github/annacrombie/kaicho.svg?branch=master&style=shields)](http://inch-ci.org/github/annacrombie/kaicho)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/kaicho.svg)](https://badge.fury.io/rb/kaicho)
|
2
6
|
|
3
7
|
Kaicho is the boss for your resources. It handles keeping everything up to
|
4
8
|
date.
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'kaicho'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "kaicho"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/bin/setup
CHANGED
data/kaicho.gemspec
CHANGED
@@ -1,27 +1,30 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require
|
5
|
+
require 'kaicho/version'
|
4
6
|
|
5
7
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
8
|
+
spec.name = 'kaicho'
|
7
9
|
spec.version = Kaicho::VERSION
|
8
|
-
spec.authors = [
|
9
|
-
spec.email = [
|
10
|
+
spec.authors = ['Stone Tickle']
|
11
|
+
spec.email = ['lattis@mochiro.moe']
|
10
12
|
|
11
|
-
spec.summary =
|
12
|
-
spec.homepage =
|
13
|
+
spec.summary = 'a resource manager'
|
14
|
+
spec.homepage = 'https://github.com/annacrombie/kaicho'
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
18
20
|
end
|
19
21
|
|
20
|
-
spec.bindir =
|
22
|
+
spec.bindir = 'exe'
|
21
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
-
spec.require_paths = [
|
24
|
+
spec.require_paths = ['lib']
|
23
25
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.16', '>=1.16.5'
|
27
|
+
spec.add_development_dependency 'rake', '~> 12.3', '>=12.3.1'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.8', '>=3.8.0'
|
29
|
+
spec.add_development_dependency 'coveralls', '~> 0.8', '>=0.8.22'
|
27
30
|
end
|
data/lib/kaicho.rb
CHANGED
@@ -1,104 +1,129 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# ```
|
13
|
-
# class Fruits
|
14
|
-
# include Kaicho
|
3
|
+
require 'kaicho/version'
|
4
|
+
require 'kaicho/util'
|
5
|
+
|
6
|
+
# Kaicho is a module for instance variable management. It can also manage
|
7
|
+
# class variables, both are referred to as ``resources.'' All class and
|
8
|
+
# instance variables are automatically considered resources, but only those
|
9
|
+
# which have been defined with {#def_resource} have the ability to be
|
10
|
+
# automatically updated.
|
15
11
|
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
# def_resource :total, depend: { apples: :fail, oranges: :fail } do
|
20
|
-
# puts "computing total"
|
21
|
-
# @apples + @oranges
|
22
|
-
# end
|
23
|
-
# end
|
24
|
-
# end
|
12
|
+
# Auto-updates occur whenever a resource is updated through {#update_resource}
|
13
|
+
# or if a resource has never been initialized and is accessed through a kaicho
|
14
|
+
# #{attr_reader}.
|
25
15
|
#
|
26
|
-
#
|
27
|
-
# f.apples #=> 0
|
28
|
-
# f.apples += 1 #=> 1
|
29
|
-
# computing total
|
30
|
-
# f.oranges = 10 #=> 10
|
31
|
-
# computing total
|
32
|
-
# f.total #=> 11
|
33
|
-
# f.oranges = 2
|
34
|
-
# computing total
|
35
|
-
# f.total #=> 13
|
36
|
-
# f.total #=> 13
|
37
|
-
# ```
|
16
|
+
# Note that all methods act on instances of Classes at the moment.
|
38
17
|
module Kaicho
|
39
18
|
# adds trigger(s) which can be used to trigger updates of resources
|
40
19
|
# who have the trigger set
|
41
20
|
#
|
42
|
-
# @param
|
43
|
-
|
21
|
+
# @param [[Symbol]] trigs a list of symbols to be used as triggers
|
22
|
+
# @return [True] this method always returns true or raises an exception
|
23
|
+
def add_triggers(*trigs)
|
44
24
|
@triggers ||= []
|
45
|
-
@triggers +=
|
25
|
+
@triggers += trigs.map(&:to_sym)
|
26
|
+
|
27
|
+
true
|
46
28
|
end
|
47
29
|
|
48
|
-
# makes both an attr_reader and an attr_writer for the
|
30
|
+
# makes both an attr_reader and an attr_writer for the +dname+
|
49
31
|
#
|
50
32
|
# @param dname the resource to create accessors for
|
51
33
|
# @param share the owner of the shared variable
|
34
|
+
# @return [True] this method always returns true or raises an exception
|
52
35
|
def attr_accessor(dname, share: nil)
|
53
|
-
attr_reader(dname, share:
|
54
|
-
attr_writer(dname, share:
|
36
|
+
attr_reader(dname, share: share)
|
37
|
+
attr_writer(dname, share: share)
|
38
|
+
|
39
|
+
true
|
55
40
|
end
|
56
41
|
|
57
|
-
#
|
58
|
-
# attr_reader but will update the resource if it hasn't been
|
59
|
-
# before.
|
42
|
+
# defines an attr_reader singleton method for a resource which functions just
|
43
|
+
# like a typical attr_reader but will update the resource if it hasn't been
|
44
|
+
# accessed before. Unlike an attr_writer, an attr_reader can only be defined
|
45
|
+
# for resources that have been previously defined using {#def_resource}.
|
46
|
+
#
|
47
|
+
# @param dname the resource that will be accessed, as well as the name of the
|
48
|
+
# singleton method.
|
60
49
|
#
|
61
|
-
# @param dname the resource that will be accessed
|
62
50
|
# @param share the owner of the shared variable
|
51
|
+
# @return [True] this method always returns true or raises an exception
|
63
52
|
def attr_reader(dname, share: nil)
|
64
|
-
|
65
|
-
|
53
|
+
@resources ||= {}
|
54
|
+
|
55
|
+
unless @resources.key?(dname)
|
56
|
+
raise(ArgumentError, "resource #{dname} has not been defined")
|
57
|
+
end
|
58
|
+
|
59
|
+
read =
|
60
|
+
if share.nil?
|
61
|
+
-> { instance_variable_get(:"@#{dname}") }
|
62
|
+
else
|
63
|
+
-> { share.class_variable_get(:"@@#{dname}") }
|
64
|
+
end
|
65
|
+
|
66
66
|
define_singleton_method(dname) do
|
67
67
|
update_resource(dname) unless @resources[dname][:udid].positive?
|
68
68
|
read.call
|
69
69
|
end
|
70
|
+
|
71
|
+
true
|
70
72
|
end
|
71
73
|
|
72
|
-
#
|
73
|
-
# attr_writer but will update the resource's dependants when
|
74
|
+
# defines an attr_writer singleton method for a resource which functions just
|
75
|
+
# like a typical attr_writer but will update the resource's dependants when
|
76
|
+
# it is called. Unlike an attr_reader, the resource +dname+ need not be
|
77
|
+
# previously defined using {#def_resource}.
|
74
78
|
#
|
75
|
-
# @param dname the resource that will be accessed
|
79
|
+
# @param dname the resource that will be accessed. The name of the singleton
|
80
|
+
# method defined will be +"#{dname}="+.
|
76
81
|
# @param share the owner of the shared variable
|
82
|
+
# @return [True] this method always returns true or raises an exception
|
77
83
|
def attr_writer(dname, share: nil)
|
78
|
-
write =
|
79
|
-
|
84
|
+
write =
|
85
|
+
if share.nil?
|
86
|
+
->(v) { instance_variable_set(:"@#{dname}", v) }
|
87
|
+
else
|
88
|
+
->(v) { share.class_variable_set(:"@@#{dname}", v) }
|
89
|
+
end
|
90
|
+
|
80
91
|
define_singleton_method(:"#{dname}=") do |v|
|
81
92
|
write.call(v)
|
82
93
|
update_dependants(dname)
|
83
94
|
v
|
84
95
|
end
|
85
|
-
end
|
86
96
|
|
87
|
-
|
88
|
-
unless expected === got
|
89
|
-
raise TypeError.new("expected #{expected.name} got #{got}:#{got.class.name}")
|
90
|
-
end
|
97
|
+
true
|
91
98
|
end
|
92
99
|
|
93
|
-
#
|
100
|
+
# Define a resource
|
94
101
|
#
|
95
|
-
# @param dname the name of the resource
|
96
|
-
# @param depends a hash of dependants with the format
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
#
|
102
|
+
# @param [Symbol] dname the name of the resource
|
103
|
+
# @param [Hash] depends a hash of dependants with the format
|
104
|
+
# +{ dependant_name: :update_action }+ where update_action is the action
|
105
|
+
# that is taken when this resource is updated. Update_action can be one of:
|
106
|
+
# - +:update+ - update the dependant before updating this resource
|
107
|
+
# - +:keep+ - keep the dependant if it is already defined, otherwise,
|
108
|
+
# update it
|
109
|
+
# - +:fail+ - don't try to update this resource if the dependant is not
|
110
|
+
# defined
|
111
|
+
# @param [Array] triggers a list of triggers. These triggers must have been
|
112
|
+
# previously defined using {#add_triggers}
|
113
|
+
# @param [Boolean] overwrite if a resource with this name already exists,
|
114
|
+
# should it be overwritten
|
115
|
+
# @param [Object, nil] share if +nil+, this resource is stored as an instance
|
116
|
+
# variable, else the value must be an instance of a class and this resource
|
117
|
+
# is stored as a class variable owned by the class specified.
|
118
|
+
# @param [Symbol] accessor a symbol that determines which attribute accessors
|
119
|
+
# should be generated for this resource
|
120
|
+
# - +:read+, +:r+ - defines an {#attr_reader}
|
121
|
+
# - +:write+, +:w+ - defines an {#attr_writer}
|
122
|
+
# - +:both+, +:rw+ - defines both, see {#attr_accessor}
|
123
|
+
# - +:none+ - don't generate any accessors
|
124
|
+
# @param block a block that will be called, with no arguments, to update this
|
125
|
+
# resource
|
126
|
+
# @return [True] this method always returns true or raises an exception
|
102
127
|
def def_resource(dname,
|
103
128
|
depends: {},
|
104
129
|
triggers: [],
|
@@ -108,39 +133,29 @@ module Kaicho
|
|
108
133
|
&block)
|
109
134
|
@resources ||= {}
|
110
135
|
|
111
|
-
check_type(Symbol, dname)
|
112
|
-
check_type(Hash, depends)
|
113
|
-
check_type(Array, triggers)
|
136
|
+
Kaicho::Util.check_type(Symbol, dname)
|
137
|
+
Kaicho::Util.check_type(Hash, depends)
|
138
|
+
Kaicho::Util.check_type(Array, triggers)
|
114
139
|
|
115
|
-
|
140
|
+
unless %i[read r write w both rw none].include?(accessor)
|
141
|
+
raise(ArgumentError, "invalid accessor: :#{accessor}")
|
142
|
+
end
|
116
143
|
|
117
144
|
add_triggers # initialize @triggers to []
|
118
145
|
triggers.each do |t|
|
119
|
-
raise
|
146
|
+
raise(ArgumentError, "invalid trigger :#{t}") unless @triggers.include?(t)
|
120
147
|
end
|
121
148
|
|
122
|
-
|
123
|
-
case depends
|
124
|
-
when Array
|
125
|
-
depends.map { |d| [d, :keep] }.to_h
|
126
|
-
when Hash
|
127
|
-
depends
|
128
|
-
else
|
129
|
-
{ depends => :keep }
|
130
|
-
end
|
149
|
+
return if @resources.key?(dname) && !overwrite
|
131
150
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
share: share,
|
141
|
-
varname: share.nil? ? "@#{dname}" : "@@#{dname}"
|
142
|
-
}
|
143
|
-
)
|
151
|
+
@resources[dname] = {
|
152
|
+
depends: depends,
|
153
|
+
proc: block,
|
154
|
+
udid: -1,
|
155
|
+
triggers: triggers,
|
156
|
+
share: share,
|
157
|
+
varname: share.nil? ? "@#{dname}" : "@@#{dname}"
|
158
|
+
}
|
144
159
|
|
145
160
|
case accessor
|
146
161
|
when :read, :r
|
@@ -150,45 +165,80 @@ module Kaicho
|
|
150
165
|
when :both, :rw
|
151
166
|
attr_accessor(dname, share: share)
|
152
167
|
end
|
168
|
+
|
169
|
+
true
|
153
170
|
end
|
154
171
|
|
172
|
+
# Determine if the value for resource has been defined. In other words,
|
173
|
+
# determine if a resource has ever been updated.
|
174
|
+
#
|
175
|
+
# If this resource has been defined using {#def_resource} then check if an
|
176
|
+
# associated instance or class variable is defined. Otherwise this method is
|
177
|
+
# eqivalent to calling +instance_variable_defined?("@#{dname}")+.
|
178
|
+
#
|
179
|
+
# @param [Symbol] dname the name of the resource
|
180
|
+
# @return [True] this method always returns true or raises an exception
|
155
181
|
def resource_defined?(dname)
|
156
182
|
return instance_variable_defined?("@#{dname}") unless @resources.key?(dname)
|
157
183
|
|
158
184
|
if @resources[dname][:share].nil?
|
159
185
|
instance_variable_defined?(@resources[dname][:varname])
|
160
186
|
else
|
161
|
-
@resources[dname][:share].class_variable_defined?(
|
187
|
+
@resources[dname][:share].class_variable_defined?(
|
188
|
+
@resources[dname][:varname]
|
189
|
+
)
|
162
190
|
end
|
163
191
|
end
|
164
192
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
193
|
+
# Update a resource
|
194
|
+
#
|
195
|
+
# This method will update the specified resource and all of its depends
|
196
|
+
# and dependants.
|
197
|
+
#
|
198
|
+
# @see #update_depends
|
199
|
+
# @see #update_dependants
|
200
|
+
#
|
201
|
+
# @param dname the name of the resource
|
202
|
+
# @param udid the update-id of this call, this should be left +nil+. It is
|
203
|
+
# internally to avoid infinite loops during update cascades.
|
204
|
+
# @return [True] this method always returns true or raises an exception
|
205
|
+
def update_resource(dname, udid = nil)
|
206
|
+
unless @resources.key?(dname)
|
207
|
+
raise(ArgumentError, "no such resource #{dname}")
|
208
|
+
end
|
169
209
|
|
170
210
|
return if @resources[dname][:udid] == udid
|
171
211
|
|
172
|
-
Zashoku.log.debug(self) { "updating resource #{dname} #{udid}" }
|
173
|
-
|
174
212
|
udid ||= rand
|
175
213
|
|
176
|
-
return unless
|
214
|
+
return unless update_depends(dname, udid)
|
177
215
|
|
178
216
|
result = @resources[dname][:proc].call
|
179
217
|
|
180
218
|
if @resources[dname][:share].nil?
|
181
219
|
instance_variable_set(@resources[dname][:varname], result)
|
182
220
|
else
|
183
|
-
@resources[dname][:share].class_variable_set(
|
221
|
+
@resources[dname][:share].class_variable_set(
|
222
|
+
@resources[dname][:varname], result
|
223
|
+
)
|
184
224
|
end
|
185
225
|
|
186
226
|
@resources[dname][:udid] = udid
|
187
227
|
|
188
228
|
update_dependants(dname, udid)
|
229
|
+
|
230
|
+
true
|
189
231
|
end
|
190
232
|
|
191
|
-
|
233
|
+
# Update the prerequisites of a resource.
|
234
|
+
#
|
235
|
+
# This method will update all resources that +dname+ depends on.
|
236
|
+
#
|
237
|
+
# @param dname the name of the resource
|
238
|
+
# @param udid the update-id of this call, this should be left +nil+. It is
|
239
|
+
# internally to avoid infinite loops during update cascades.
|
240
|
+
# @return [True] this method always returns true or raises an exception
|
241
|
+
def update_depends(dname, udid = nil)
|
192
242
|
udid ||= rand
|
193
243
|
@resources[dname][:depends].each do |d, o|
|
194
244
|
case o
|
@@ -197,34 +247,56 @@ module Kaicho
|
|
197
247
|
when :keep
|
198
248
|
update_resource(d, udid) unless resource_defined?(d)
|
199
249
|
when :fail
|
200
|
-
unless resource_defined?(d)
|
201
|
-
Zashoku.log.debug(self) { "update resource #{dname} failing on #{d}" }
|
202
|
-
return false
|
203
|
-
end
|
204
|
-
when :force
|
205
|
-
update_resource(d, udid)
|
206
|
-
else
|
207
|
-
raise "option #{o} not understood for #{d} while updating #{dname}"
|
250
|
+
return false unless resource_defined?(d)
|
208
251
|
end
|
209
|
-
true
|
210
252
|
end
|
253
|
+
|
254
|
+
true
|
211
255
|
end
|
212
256
|
|
213
|
-
|
257
|
+
# Update the dependants of +dname+
|
258
|
+
#
|
259
|
+
# This method will update all resources that have +dname+ in their list of
|
260
|
+
# depends.
|
261
|
+
#
|
262
|
+
# @param dname the name of the resource
|
263
|
+
# @param udid the update-id of this call, this should be left +nil+. It is
|
264
|
+
# internally to avoid infinite loops during update cascades.
|
265
|
+
# @return [True] this method always returns true or raises an exception
|
266
|
+
def update_dependants(dname, udid = nil)
|
214
267
|
udid ||= rand
|
215
|
-
|
216
|
-
|
217
|
-
|
268
|
+
dependants = @resources.select do |_, v|
|
269
|
+
v[:depends].include?(dname) && v[:udid] != udid
|
270
|
+
end
|
271
|
+
dependants.each { |d, _| update_resource(d, udid) }
|
272
|
+
|
273
|
+
true
|
218
274
|
end
|
219
275
|
|
276
|
+
# Trigger resource updates
|
277
|
+
#
|
278
|
+
# This method will update all resources that have +trigger+ in their list of
|
279
|
+
# triggers.
|
280
|
+
#
|
281
|
+
# @param [Symbol] trigger the name of the trigger to trigger
|
282
|
+
# @return [True] this method always returns true or raises an exception
|
220
283
|
def trigger_resources(trigger)
|
221
284
|
udid = rand
|
222
|
-
res = @resources.select { |_,v| v[:triggers].include?(trigger) }
|
223
|
-
res.each { |r,_| update_resource(r, udid) }
|
285
|
+
res = @resources.select { |_, v| v[:triggers].include?(trigger) }
|
286
|
+
res.each { |r, _| update_resource(r, udid) }
|
287
|
+
|
288
|
+
true
|
224
289
|
end
|
225
290
|
|
291
|
+
# Update all resources
|
292
|
+
#
|
293
|
+
# Equivalent to calling {#update_resource} for each resource in +@resources+.
|
294
|
+
#
|
295
|
+
# @return [True] this method always returns true or raises an exception
|
226
296
|
def update_all_resources
|
227
297
|
udid = rand
|
228
298
|
@resources.keys.each { |d| update_resource(d, udid) }
|
299
|
+
|
300
|
+
true
|
229
301
|
end
|
230
302
|
end
|
data/lib/kaicho/util.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kaicho
|
4
|
+
# A utility module for Kaicho. Don't touch this stuff!
|
5
|
+
module Util
|
6
|
+
module_function
|
7
|
+
|
8
|
+
# raise an exception if a type is invalid
|
9
|
+
#
|
10
|
+
# @param [Class] expected the expected type
|
11
|
+
# @param [Instance] got the received type
|
12
|
+
# @return [True] this method always returns true or raises an exception
|
13
|
+
def check_type(expected, got)
|
14
|
+
unless expected === got
|
15
|
+
raise(
|
16
|
+
TypeError,
|
17
|
+
"expected #{expected.name} got #{got}:#{got.class.name}"
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
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.
|
4
|
+
version: 0.2.0
|
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-10-
|
11
|
+
date: 2018-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.16'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.16.5
|
20
23
|
type: :development
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,34 +27,69 @@ dependencies:
|
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '1.16'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.16.5
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rake
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
39
|
+
version: '12.3'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 12.3.1
|
34
43
|
type: :development
|
35
44
|
prerelease: false
|
36
45
|
version_requirements: !ruby/object:Gem::Requirement
|
37
46
|
requirements:
|
38
47
|
- - "~>"
|
39
48
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
49
|
+
version: '12.3'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 12.3.1
|
41
53
|
- !ruby/object:Gem::Dependency
|
42
54
|
name: rspec
|
43
55
|
requirement: !ruby/object:Gem::Requirement
|
44
56
|
requirements:
|
45
57
|
- - "~>"
|
46
58
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
59
|
+
version: '3.8'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 3.8.0
|
48
63
|
type: :development
|
49
64
|
prerelease: false
|
50
65
|
version_requirements: !ruby/object:Gem::Requirement
|
51
66
|
requirements:
|
52
67
|
- - "~>"
|
53
68
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
69
|
+
version: '3.8'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 3.8.0
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: coveralls
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - "~>"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0.8'
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.8.22
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.8'
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 0.8.22
|
55
93
|
description:
|
56
94
|
email:
|
57
95
|
- lattis@mochiro.moe
|
@@ -63,12 +101,14 @@ files:
|
|
63
101
|
- ".rspec"
|
64
102
|
- ".travis.yml"
|
65
103
|
- Gemfile
|
104
|
+
- Gemfile.lock
|
66
105
|
- README.md
|
67
106
|
- Rakefile
|
68
107
|
- bin/console
|
69
108
|
- bin/setup
|
70
109
|
- kaicho.gemspec
|
71
110
|
- lib/kaicho.rb
|
111
|
+
- lib/kaicho/util.rb
|
72
112
|
- lib/kaicho/version.rb
|
73
113
|
homepage: https://github.com/annacrombie/kaicho
|
74
114
|
licenses: []
|