yuuki 0.1.10 → 0.1.12
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/bin/console +1 -0
- data/lib/yuuki/caller.rb +19 -20
- data/lib/yuuki/periodic.rb +7 -6
- data/lib/yuuki/runner.rb +14 -10
- data/lib/yuuki/version.rb +1 -1
- data/sig/yuuki/runner.rbs +1 -1
- data/yuuki.gemspec +1 -0
- metadata +17 -7
- data/.rubocop.yml +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7409615113f6585101139dd2df95c8f737d0f291016351b152bc3e01390ab8d0
|
4
|
+
data.tar.gz: 3941d1d916033d8cbf5944f55cad051f74213d8d0d809476d155800b60204b5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a7dc76ec6ac0d04fbc8a734a5e79994a3f58fbb1f8d8c888c586e66442ce1eb5398ce9e1a413c9edb0145a3bfeb479843bbc2c721dd317305fdeb242bac8e3c
|
7
|
+
data.tar.gz: b22db32336dcceced700ffb15b65221c8020db7243df8b9cf79adc7a9d6a51426cfade7826a38045e74eb5da4d2ce5b2df0d76c2a90a5924591fe65c76fe9373
|
data/bin/console
CHANGED
data/lib/yuuki/caller.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'set'
|
4
3
|
require 'yuuki/runner'
|
5
4
|
require 'yoshinon'
|
6
5
|
|
@@ -10,7 +9,7 @@ module Yuuki
|
|
10
9
|
# @param [String] require_dir directory
|
11
10
|
# @param [Boolean] recursive
|
12
11
|
def self.require_dir(require_dir, recursive: false)
|
13
|
-
Dir.glob(recursive ? "#{require_dir}/**/*.rb" : "#{require_dir}/*.rb").
|
12
|
+
Dir.glob(recursive ? "#{require_dir}/**/*.rb" : "#{require_dir}/*.rb").each { |file| require file }
|
14
13
|
end
|
15
14
|
|
16
15
|
# @param [Object] instances
|
@@ -56,33 +55,33 @@ module Yuuki
|
|
56
55
|
def runners
|
57
56
|
list = @instances.flat_map do |instance|
|
58
57
|
methods = instance.class.instance_variable_get(:@yuuki_methods)
|
59
|
-
methods.select {|_sig, meta| meta[:enabled]}.map {|sig, meta| [instance.method(sig), meta]}
|
58
|
+
methods.select { |_sig, meta| meta[:enabled] }.map { |sig, meta| [instance.method(sig), meta] }
|
60
59
|
end
|
61
|
-
list.sort_by {|_method, meta| -(meta[:priority] || 0)}
|
60
|
+
list.sort_by { |_method, meta| -(meta[:priority] || 0) }
|
62
61
|
end
|
63
62
|
|
64
63
|
# returns all tags defined as Set
|
65
64
|
def tags
|
66
65
|
tags = @instances.flat_map do |instance|
|
67
66
|
methods = instance.class.instance_variable_get(:@yuuki_methods)
|
68
|
-
methods.select {|_sig, meta| meta[:enabled]}.flat_map {|_sig, meta| meta[:tags]}
|
67
|
+
methods.select { |_sig, meta| meta[:enabled] }.flat_map { |_sig, meta| meta[:tags] }
|
69
68
|
end
|
70
69
|
ret = Set.new
|
71
|
-
tags.each {|e| ret += e if e}
|
70
|
+
tags.each { |e| ret += e if e }
|
72
71
|
ret
|
73
72
|
end
|
74
73
|
|
75
74
|
# runs all methods
|
76
75
|
# @param [Object] args arguments
|
77
|
-
def run(**args, &
|
78
|
-
run_internal(runners, args, &
|
76
|
+
def run(**args, &)
|
77
|
+
run_internal(runners, args, &)
|
79
78
|
end
|
80
79
|
|
81
80
|
# runs all selected methods
|
82
81
|
# @param [Proc] proc_select
|
83
82
|
# @param [Object] args arguments
|
84
|
-
def run_select(proc_select, **args, &
|
85
|
-
run_internal(runners.select(&proc_select), args, &
|
83
|
+
def run_select(proc_select, **args, &)
|
84
|
+
run_internal(runners.select(&proc_select), args, &)
|
86
85
|
end
|
87
86
|
|
88
87
|
# set whether to ignore ``tag not associated'' error
|
@@ -91,9 +90,9 @@ module Yuuki
|
|
91
90
|
end
|
92
91
|
|
93
92
|
# runs all methods with the specified tags
|
94
|
-
# @param [Symbol] tags
|
93
|
+
# @param [Array<Symbol>] tags
|
95
94
|
# @param [Object] args arguments
|
96
|
-
def run_tag(*tags, **args, &
|
95
|
+
def run_tag(*tags, **args, &)
|
97
96
|
t = self.tags
|
98
97
|
tags.each do |e|
|
99
98
|
next if t.include?(e)
|
@@ -101,20 +100,20 @@ module Yuuki
|
|
101
100
|
|
102
101
|
warn "Yuuki Warning: tag `#{e}` is not associated"
|
103
102
|
end
|
104
|
-
run_select(proc {|_method, meta| meta[:tags]&.intersect?(tags)}, **args, &
|
103
|
+
run_select(proc { |_method, meta| meta[:tags]&.intersect?(tags) }, **args, &)
|
105
104
|
end
|
106
105
|
|
107
106
|
# runs the specific method
|
108
107
|
# @param [Class, nil] klass
|
109
108
|
# @param [Symbol, nil] method_sig method name
|
110
109
|
# @param [Object] args arguments
|
111
|
-
def run_method(klass, method_sig, **args, &
|
110
|
+
def run_method(klass, method_sig, **args, &)
|
112
111
|
select_proc = proc do |method, _meta|
|
113
112
|
flag_klass = klass ? method.receiver.instance_of?(klass) : true
|
114
113
|
flag_method = method_sig ? method.name == method_sig : true
|
115
114
|
flag_klass && flag_method
|
116
115
|
end
|
117
|
-
run_select(select_proc, **args, &
|
116
|
+
run_select(select_proc, **args, &)
|
118
117
|
end
|
119
118
|
|
120
119
|
# joins all runnning threads
|
@@ -171,8 +170,8 @@ module Yuuki
|
|
171
170
|
|
172
171
|
if nonspecified_last_opt
|
173
172
|
# if there already exist non-specified :opt arguments, no more specified :opt argument is allowed
|
174
|
-
raise Yuuki::Error, "A required argument '#{nonspecified_last_opt}' was not found"\
|
175
|
-
|
173
|
+
raise Yuuki::Error, "A required argument '#{nonspecified_last_opt}' was not found " \
|
174
|
+
"on running #{method.owner}::#{method.name}" + " with optional argument '#{name}'"
|
176
175
|
end
|
177
176
|
params_array << args[name]
|
178
177
|
when :rest
|
@@ -180,8 +179,8 @@ module Yuuki
|
|
180
179
|
|
181
180
|
if nonspecified_last_opt
|
182
181
|
# if there already exist non-specified :opt arguments, the :rest argument cannot be handled
|
183
|
-
raise Yuuki::Error, "A required argument '#{nonspecified_last_opt}' not found"\
|
184
|
-
|
182
|
+
raise Yuuki::Error, "A required argument '#{nonspecified_last_opt}' not found " \
|
183
|
+
"on running #{method.owner}::#{method.name}" + " with rest argument '#{name}'"
|
185
184
|
end
|
186
185
|
if args[name].respond_to?(:to_ary)
|
187
186
|
params_array += args[name]
|
@@ -209,7 +208,7 @@ module Yuuki
|
|
209
208
|
params_block = args[name]
|
210
209
|
end
|
211
210
|
end
|
212
|
-
params_block = block unless params.any? {|type, _| type == :block}
|
211
|
+
params_block = block unless params.any? { |type, _| type == :block }
|
213
212
|
params_hash.empty? ? method[*params_array, ¶ms_block] : method[*params_array, **params_hash, ¶ms_block]
|
214
213
|
ensure
|
215
214
|
yoshinon&.unlock
|
data/lib/yuuki/periodic.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'English'
|
3
4
|
require 'yuuki/caller'
|
4
5
|
require 'yuuki/runner'
|
5
6
|
require 'yoshinon'
|
@@ -7,7 +8,7 @@ require 'yoshinon'
|
|
7
8
|
module Yuuki
|
8
9
|
module Runner
|
9
10
|
# sets interval to the method
|
10
|
-
# @param [Symbol] methods method names
|
11
|
+
# @param [Array<Symbol>] methods method names
|
11
12
|
# @param [Integer] interval
|
12
13
|
def periodic(*methods, interval)
|
13
14
|
@yuuki_methods ||= {}
|
@@ -18,7 +19,7 @@ module Yuuki
|
|
18
19
|
end
|
19
20
|
|
20
21
|
# sets whether the method run at the first time
|
21
|
-
# @param [Symbol] methods method names
|
22
|
+
# @param [Array<Symbol>] methods method names
|
22
23
|
# @param [Boolean] enabled
|
23
24
|
def first_run(*methods, enabled: true)
|
24
25
|
@yuuki_methods ||= {}
|
@@ -51,7 +52,7 @@ module Yuuki
|
|
51
52
|
# runs the periodic caller
|
52
53
|
# @param [Numeric] gmtoff GMT Offset
|
53
54
|
# @param [Object] args arguments
|
54
|
-
def run(gmtoff = Time.now.gmtoff, **args, &
|
55
|
+
def run(gmtoff = Time.now.gmtoff, **args, &)
|
55
56
|
last_time = nil
|
56
57
|
loop do
|
57
58
|
@current_time = Time.now.to_f
|
@@ -65,14 +66,14 @@ module Yuuki
|
|
65
66
|
l = last_time + gmtoff
|
66
67
|
(l.div(meta[:periodic]) + 1) * meta[:periodic] <= c
|
67
68
|
end
|
68
|
-
run_select(select_proc, **args, &
|
69
|
+
run_select(select_proc, **args, &)
|
69
70
|
rescue StandardError
|
70
|
-
@on_error ? @on_error[
|
71
|
+
@on_error ? @on_error[$ERROR_INFO] : raise
|
71
72
|
end
|
72
73
|
@first_run = false
|
73
74
|
|
74
75
|
last_time = @current_time
|
75
|
-
((@current_time + 1).floor - Time.now.to_f).tap {|e| sleep e if e > 0}
|
76
|
+
((@current_time + 1).floor - Time.now.to_f).tap { |e| sleep e if e > 0 }
|
76
77
|
end
|
77
78
|
end
|
78
79
|
end
|
data/lib/yuuki/runner.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'set'
|
4
|
-
|
5
3
|
module Yuuki
|
6
4
|
module Runner
|
5
|
+
def self.extended(base)
|
6
|
+
base.define_method(:yuuki) do
|
7
|
+
@yuuki
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
7
11
|
# adds methods to yuuki
|
8
|
-
# @param [Symbol] methods method names
|
12
|
+
# @param [Array<Symbol>] methods method names
|
9
13
|
def add(*methods)
|
10
14
|
@yuuki_methods ||= {}
|
11
15
|
methods.each do |method|
|
@@ -15,7 +19,7 @@ module Yuuki
|
|
15
19
|
end
|
16
20
|
|
17
21
|
# deletes methods from yuuki
|
18
|
-
# @param [Symbol] methods method names
|
22
|
+
# @param [Array<Symbol>] methods method names
|
19
23
|
def delete(*methods)
|
20
24
|
@yuuki_methods ||= {}
|
21
25
|
methods.each do |method|
|
@@ -26,7 +30,7 @@ module Yuuki
|
|
26
30
|
|
27
31
|
# adds tags to the method
|
28
32
|
# @param [Symbol] method method name
|
29
|
-
# @param [Symbol] tags tag names
|
33
|
+
# @param [Array<Symbol>] tags tag names
|
30
34
|
def tag(method, *tags)
|
31
35
|
@yuuki_methods ||= {}
|
32
36
|
@yuuki_methods[method] ||= {}
|
@@ -35,7 +39,7 @@ module Yuuki
|
|
35
39
|
end
|
36
40
|
|
37
41
|
# enables threading for the methods
|
38
|
-
# @param [Symbol] methods method names
|
42
|
+
# @param [Array<Symbol>] methods method names
|
39
43
|
# @param [Boolean] enabled
|
40
44
|
def thread(*methods, enabled: true)
|
41
45
|
@yuuki_methods ||= {}
|
@@ -46,13 +50,13 @@ module Yuuki
|
|
46
50
|
end
|
47
51
|
|
48
52
|
# sets priority to the method
|
49
|
-
# @param [Symbol] methods method names
|
50
|
-
# @param [Numeric]
|
51
|
-
def priority(*methods,
|
53
|
+
# @param [Array<Symbol>] methods method names
|
54
|
+
# @param [Numeric] value
|
55
|
+
def priority(*methods, value)
|
52
56
|
@yuuki_methods ||= {}
|
53
57
|
methods.each do |method|
|
54
58
|
@yuuki_methods[method] ||= {}
|
55
|
-
@yuuki_methods[method][:priority] =
|
59
|
+
@yuuki_methods[method][:priority] = value
|
56
60
|
end
|
57
61
|
end
|
58
62
|
end
|
data/lib/yuuki/version.rb
CHANGED
data/sig/yuuki/runner.rbs
CHANGED
@@ -9,6 +9,6 @@ module Yuuki
|
|
9
9
|
def delete: (*Symbol methods) -> void
|
10
10
|
def tag: (Symbol method, *Symbol tags) -> void
|
11
11
|
def thread: (*Symbol methods, ?enabled: bool) -> void
|
12
|
-
def priority: (*Symbol methods, Numeric
|
12
|
+
def priority: (*Symbol methods, Numeric value) -> void
|
13
13
|
end
|
14
14
|
end
|
data/yuuki.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yuuki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ishotihadus
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-08-03 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: yoshinon
|
@@ -38,6 +37,20 @@ dependencies:
|
|
38
37
|
- - ">="
|
39
38
|
- !ruby/object:Gem::Version
|
40
39
|
version: '0'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: minitest
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
41
54
|
- !ruby/object:Gem::Dependency
|
42
55
|
name: pry
|
43
56
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,7 +88,6 @@ extra_rdoc_files: []
|
|
75
88
|
files:
|
76
89
|
- ".DS_Store"
|
77
90
|
- ".gitignore"
|
78
|
-
- ".rubocop.yml"
|
79
91
|
- Gemfile
|
80
92
|
- LICENSE.txt
|
81
93
|
- README.md
|
@@ -98,7 +110,6 @@ homepage: https://github.com/ishotihadus/yuuki
|
|
98
110
|
licenses:
|
99
111
|
- MIT
|
100
112
|
metadata: {}
|
101
|
-
post_install_message:
|
102
113
|
rdoc_options: []
|
103
114
|
require_paths:
|
104
115
|
- lib
|
@@ -113,8 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
124
|
- !ruby/object:Gem::Version
|
114
125
|
version: '0'
|
115
126
|
requirements: []
|
116
|
-
rubygems_version: 3.
|
117
|
-
signing_key:
|
127
|
+
rubygems_version: 3.6.2
|
118
128
|
specification_version: 4
|
119
129
|
summary: A caller / runner framework for Ruby
|
120
130
|
test_files: []
|
data/.rubocop.yml
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
AllCops:
|
2
|
-
TargetRubyVersion: 2.6
|
3
|
-
|
4
|
-
Metrics/AbcSize:
|
5
|
-
Max: 170
|
6
|
-
|
7
|
-
Metrics/BlockLength:
|
8
|
-
Max: 250
|
9
|
-
|
10
|
-
Metrics/ClassLength:
|
11
|
-
Max: 1000
|
12
|
-
|
13
|
-
Metrics/CyclomaticComplexity:
|
14
|
-
Max: 70
|
15
|
-
|
16
|
-
Metrics/MethodLength:
|
17
|
-
Max: 100
|
18
|
-
|
19
|
-
Metrics/ModuleLength:
|
20
|
-
Max: 1000
|
21
|
-
|
22
|
-
Metrics/ParameterLists:
|
23
|
-
Max: 50
|
24
|
-
|
25
|
-
Metrics/PerceivedComplexity:
|
26
|
-
Max: 80
|
27
|
-
|
28
|
-
Layout/SpaceInsideBlockBraces:
|
29
|
-
EnforcedStyle: no_space
|
30
|
-
SpaceBeforeBlockParameters: false
|
31
|
-
|
32
|
-
Style/Documentation:
|
33
|
-
Enabled: false
|
34
|
-
|
35
|
-
Style/NumericPredicate:
|
36
|
-
EnforcedStyle: comparison
|
37
|
-
|
38
|
-
Style/MultilineBlockChain:
|
39
|
-
Enabled: false
|
40
|
-
|
41
|
-
Style/SpecialGlobalVars:
|
42
|
-
EnforcedStyle: use_perl_names
|