yuuki 0.1.1 → 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/.DS_Store +0 -0
- data/README.md +4 -0
- data/lib/yuuki/caller.rb +41 -9
- data/lib/yuuki/periodic.rb +25 -9
- data/lib/yuuki/runner.rb +13 -5
- data/lib/yuuki/version.rb +1 -1
- data/sig/yuuki/caller.rbs +25 -0
- data/sig/yuuki/error.rbs +7 -0
- data/sig/yuuki/periodic.rbs +19 -0
- data/sig/yuuki/runner.rbs +14 -0
- data/sig/yuuki/version.rbs +6 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbc6115f9c7818a9c171c7c8928321bdd7c5fd737ce7f1cbed4024c56dfd2d91
|
4
|
+
data.tar.gz: 148536d6a0e91a93994f12cb4672b8cdafe1e77e476b89532455bbcf47f3aaa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89b3a2e35810e21a94a096debaa2d709806702340ef23a0fcbe55cc73656cf263f8bef4ddbc4fbacf47c62516821dc94d11ad23948bdb0911bfcb49cb0271527
|
7
|
+
data.tar.gz: 7b67f83e432c5da9d028fbd417c2f08b6c4007dc0bdb31e836c4ad4aa691c98f3c64d02e54b0c9c8f2141d40f64332d97e71b6f3f5ea8559442a1b796b57828b
|
data/.DS_Store
ADDED
Binary file
|
data/README.md
CHANGED
data/lib/yuuki/caller.rb
CHANGED
@@ -5,37 +5,46 @@ require 'yuuki/runner'
|
|
5
5
|
|
6
6
|
module Yuuki
|
7
7
|
class Caller
|
8
|
-
|
8
|
+
# requires all the rb files in the given directory
|
9
|
+
# @param [String] require_dir directory
|
10
|
+
# @param [Boolean] recursive
|
11
|
+
def self.require_dir(require_dir, recursive: false)
|
9
12
|
Dir.glob(recursive ? "#{require_dir}/**/*.rb" : "#{require_dir}/*.rb"){|file| require file}
|
10
13
|
end
|
11
14
|
|
15
|
+
# @param [Object] instances
|
12
16
|
def initialize(*instances)
|
13
17
|
@instances = Set.new
|
14
18
|
@threads = []
|
15
19
|
add(*instances)
|
16
20
|
end
|
17
21
|
|
22
|
+
# adds instances to yuuki
|
23
|
+
# @param [Object] instances
|
18
24
|
def add(*instances)
|
19
25
|
instances.each do |instance|
|
20
26
|
# create instance if class is given
|
21
27
|
if instance.is_a?(Class)
|
22
28
|
klass = instance
|
23
|
-
|
29
|
+
# check the klass is extended
|
30
|
+
raise Yuuki::Error, 'Runner instance must be extend Yuuki::Runner' unless klass.singleton_class.include?(Yuuki::Runner)
|
31
|
+
instance = instance.allocate
|
32
|
+
instance.instance_variable_set(:@yuuki, self)
|
33
|
+
instance.send(:initialize)
|
24
34
|
else
|
25
|
-
klass
|
35
|
+
# check the klass is extended
|
36
|
+
raise Yuuki::Error, 'Runner instance must be extend Yuuki::Runner' unless instance.class.singleton_class.include?(Yuuki::Runner)
|
37
|
+
# add @yuuki to the instance
|
38
|
+
instance.instance_variable_set(:@yuuki, self)
|
26
39
|
end
|
27
40
|
|
28
|
-
# check the klass is extended
|
29
|
-
raise Yuuki::Error, 'Runner instance must be extend Yuuki::Runner' unless klass.singleton_class.include?(Yuuki::Runner)
|
30
|
-
|
31
|
-
# add @yuuki to the instance
|
32
|
-
instance.instance_variable_set(:@yuuki, self)
|
33
|
-
|
34
41
|
# regist
|
35
42
|
@instances << instance
|
36
43
|
end
|
37
44
|
end
|
38
45
|
|
46
|
+
# returns runners
|
47
|
+
# @return [Array<[Method, Hash<Symbol, Object>]>]
|
39
48
|
def runners
|
40
49
|
list = @instances.flat_map do |instance|
|
41
50
|
methods = instance.class.instance_variable_get(:@yuuki_methods)
|
@@ -44,18 +53,38 @@ module Yuuki
|
|
44
53
|
list.sort_by{|_method, meta| -(meta[:priority] || 0)}
|
45
54
|
end
|
46
55
|
|
56
|
+
# returns all tags defined
|
57
|
+
def tags
|
58
|
+
@instances.flat_map do |instance|
|
59
|
+
methods = instance.class.instance_variable_get(:@yuuki_methods)
|
60
|
+
methods.select{|_sig, meta| meta[:enabled]}.flat_map{|_sig, meta| meta[:tags]}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# runs all methods
|
65
|
+
# @param [Object] args arguments
|
47
66
|
def run(**args, &block)
|
48
67
|
run_internal(runners, args, &block)
|
49
68
|
end
|
50
69
|
|
70
|
+
# runs all selected methods
|
71
|
+
# @param [Proc] proc_select
|
72
|
+
# @param [Object] args arguments
|
51
73
|
def run_select(proc_select, **args, &block)
|
52
74
|
run_internal(runners.select(&proc_select), args, &block)
|
53
75
|
end
|
54
76
|
|
77
|
+
# runs all methods with the specified tags
|
78
|
+
# @param [Symbol] tags
|
79
|
+
# @param [Object] args arguments
|
55
80
|
def run_tag(*tags, **args, &block)
|
56
81
|
run_select(proc{|_method, meta| meta[:tags]&.intersect?(tags)}, **args, &block)
|
57
82
|
end
|
58
83
|
|
84
|
+
# runs the specific method
|
85
|
+
# @param [Class, nil] klass
|
86
|
+
# @param [Symbol, nil] method_sig method name
|
87
|
+
# @param [Object] args arguments
|
59
88
|
def run_method(klass, method_sig, **args, &block)
|
60
89
|
select_proc = proc do |method, _meta|
|
61
90
|
flag_klass = klass ? method.receiver.instance_of?(klass) : true
|
@@ -65,11 +94,14 @@ module Yuuki
|
|
65
94
|
run_select(select_proc, **args, &block)
|
66
95
|
end
|
67
96
|
|
97
|
+
# joins all runnning threads
|
68
98
|
def join
|
69
99
|
@threads.each(&:join)
|
70
100
|
@threads.select!(&:alive?)
|
71
101
|
end
|
72
102
|
|
103
|
+
# returns whether any thread is alive
|
104
|
+
# @return [Boolean]
|
73
105
|
def alive?
|
74
106
|
@threads.select!(&:alive?)
|
75
107
|
!@threads.empty?
|
data/lib/yuuki/periodic.rb
CHANGED
@@ -5,23 +5,33 @@ require 'yuuki/runner'
|
|
5
5
|
|
6
6
|
module Yuuki
|
7
7
|
module Runner
|
8
|
-
#
|
9
|
-
|
8
|
+
# sets interval to the method
|
9
|
+
# @param [Symbol] methods method names
|
10
|
+
# @param [Integer] interval
|
11
|
+
def periodic(*methods, interval)
|
10
12
|
@yuuki_methods ||= {}
|
11
|
-
|
12
|
-
|
13
|
+
methods.each do |method|
|
14
|
+
@yuuki_methods[method] ||= {}
|
15
|
+
@yuuki_methods[method][:periodic] = interval
|
16
|
+
end
|
13
17
|
end
|
14
|
-
|
15
|
-
#
|
16
|
-
|
18
|
+
|
19
|
+
# sets whether the method run at the first time
|
20
|
+
# @param [Symbol] methods method names
|
21
|
+
# @param [Boolean] enabled
|
22
|
+
def first_run(*methods, enabled: true)
|
17
23
|
@yuuki_methods ||= {}
|
18
|
-
|
19
|
-
|
24
|
+
methods.each do |method|
|
25
|
+
@yuuki_methods[method] ||= {}
|
26
|
+
@yuuki_methods[method][:first_run] = enabled
|
27
|
+
end
|
20
28
|
end
|
21
29
|
end
|
22
30
|
end
|
23
31
|
|
24
32
|
module Yuuki
|
33
|
+
# @attr_reader [Boolean] first_run
|
34
|
+
# @attr_reader [Float] current_time
|
25
35
|
class PeriodicCaller < Caller
|
26
36
|
attr_reader :first_run, :current_time
|
27
37
|
|
@@ -30,10 +40,16 @@ module Yuuki
|
|
30
40
|
@first_run = true
|
31
41
|
end
|
32
42
|
|
43
|
+
# sets error callback
|
44
|
+
# @yield [error]
|
45
|
+
# @yieldparam [Exception] error
|
33
46
|
def on_error(&block)
|
34
47
|
@on_error = block
|
35
48
|
end
|
36
49
|
|
50
|
+
# runs the periodic caller
|
51
|
+
# @param [Numeric] gmtoff GMT Offset
|
52
|
+
# @param [Object] args arguments
|
37
53
|
def run(gmtoff = Time.now.gmtoff, **args, &block)
|
38
54
|
last_time = nil
|
39
55
|
loop do
|
data/lib/yuuki/runner.rb
CHANGED
@@ -4,7 +4,8 @@ require 'set'
|
|
4
4
|
|
5
5
|
module Yuuki
|
6
6
|
module Runner
|
7
|
-
#
|
7
|
+
# adds methods to yuuki
|
8
|
+
# @param [Symbol] methods method names
|
8
9
|
def add(*methods)
|
9
10
|
@yuuki_methods ||= {}
|
10
11
|
methods.each do |method|
|
@@ -13,7 +14,8 @@ module Yuuki
|
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
|
-
#
|
17
|
+
# deletes methods from yuuki
|
18
|
+
# @param [Symbol] methods method names
|
17
19
|
def delete(*methods)
|
18
20
|
@yuuki_methods ||= {}
|
19
21
|
methods.each do |method|
|
@@ -22,7 +24,9 @@ module Yuuki
|
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
|
-
#
|
27
|
+
# adds tags to the method
|
28
|
+
# @param [Symbol] method method name
|
29
|
+
# @param [Symbol] tags tag names
|
26
30
|
def tag(method, *tags)
|
27
31
|
@yuuki_methods ||= {}
|
28
32
|
@yuuki_methods[method] ||= {}
|
@@ -30,7 +34,9 @@ module Yuuki
|
|
30
34
|
@yuuki_methods[method][:tags].merge(tags)
|
31
35
|
end
|
32
36
|
|
33
|
-
#
|
37
|
+
# enables threading for the methods
|
38
|
+
# @param [Symbol] methods method names
|
39
|
+
# @param [Boolean] enabled
|
34
40
|
def thread(*methods, enabled: true)
|
35
41
|
@yuuki_methods ||= {}
|
36
42
|
methods.each do |method|
|
@@ -39,7 +45,9 @@ module Yuuki
|
|
39
45
|
end
|
40
46
|
end
|
41
47
|
|
42
|
-
#
|
48
|
+
# sets priority to the method
|
49
|
+
# @param [Symbol] methods method names
|
50
|
+
# @param [Numeric] priority
|
43
51
|
def priority(*methods, priority)
|
44
52
|
@yuuki_methods ||= {}
|
45
53
|
methods.each do |method|
|
data/lib/yuuki/version.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
# TypeProf 0.21.2
|
2
|
+
|
3
|
+
# Classes
|
4
|
+
module Yuuki
|
5
|
+
class Caller
|
6
|
+
@instances: Set[untyped]
|
7
|
+
@threads: Array[Thread]
|
8
|
+
|
9
|
+
def self.require_dir: (String require_dir, ?recursive: bool) -> void
|
10
|
+
def initialize: (*untyped instances) -> void
|
11
|
+
def add: (*untyped instances) -> void
|
12
|
+
def runners: -> Array[untyped]
|
13
|
+
def run: (**untyped) -> void
|
14
|
+
def run_select: (^(Method, Hash[Symbol, untyped]) -> bool proc_select, **untyped) -> void
|
15
|
+
def run_tag: (*Symbol tags, **untyped) -> void
|
16
|
+
def run_method: (Class klass, Symbol method_sig, **untyped) -> void
|
17
|
+
def join: -> void
|
18
|
+
def alive?: -> bool
|
19
|
+
alias running? alive?
|
20
|
+
|
21
|
+
private
|
22
|
+
def run_internal: (Array[untyped] runners, Hash[Symbol, untyped] args) -> void
|
23
|
+
def run_method_internal: (Method method, Hash[Symbol, untyped] args) -> void
|
24
|
+
end
|
25
|
+
end
|
data/sig/yuuki/error.rbs
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# TypeProf 0.21.2
|
2
|
+
|
3
|
+
# Classes
|
4
|
+
module Yuuki
|
5
|
+
module Runner
|
6
|
+
def periodic: (Symbol method, Integer interval) -> void
|
7
|
+
def first_run: (Symbol method, ?enabled: bool) -> void
|
8
|
+
end
|
9
|
+
|
10
|
+
class PeriodicCaller < Caller
|
11
|
+
@on_error: Proc
|
12
|
+
|
13
|
+
attr_reader first_run: bool
|
14
|
+
attr_reader current_time: Float
|
15
|
+
def initialize: (*untyped instances) -> void
|
16
|
+
def on_error: {(Exception) -> void} -> void
|
17
|
+
def run: (?Integer gmtoff, **untyped) -> void
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# TypeProf 0.21.2
|
2
|
+
|
3
|
+
# Classes
|
4
|
+
module Yuuki
|
5
|
+
module Runner
|
6
|
+
@yuuki_methods: Hash[Symbol, Hash[Symbol, untyped]]
|
7
|
+
|
8
|
+
def add: (*Symbol methods) -> void
|
9
|
+
def delete: (*Symbol methods) -> void
|
10
|
+
def tag: (Symbol method, *Symbol tags) -> void
|
11
|
+
def thread: (*Symbol methods, ?enabled: bool) -> void
|
12
|
+
def priority: (*Symbol methods, Numeric priority) -> void
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ishotihadus
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -59,6 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".DS_Store"
|
62
63
|
- ".gitignore"
|
63
64
|
- Gemfile
|
64
65
|
- LICENSE.txt
|
@@ -72,6 +73,11 @@ files:
|
|
72
73
|
- lib/yuuki/periodic.rb
|
73
74
|
- lib/yuuki/runner.rb
|
74
75
|
- lib/yuuki/version.rb
|
76
|
+
- sig/yuuki/caller.rbs
|
77
|
+
- sig/yuuki/error.rbs
|
78
|
+
- sig/yuuki/periodic.rbs
|
79
|
+
- sig/yuuki/runner.rbs
|
80
|
+
- sig/yuuki/version.rbs
|
75
81
|
- yuuki.gemspec
|
76
82
|
homepage: https://github.com/ishotihadus/yuuki
|
77
83
|
licenses:
|