Class: Yuuki::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/yuuki/runner.rb,
sig/yuuki/runner.rbs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#yuukiCaller? (readonly)

Returns the value of attribute yuuki.

Returns:



5
6
7
# File 'lib/yuuki/runner.rb', line 5

def yuuki
  @yuuki
end

Class Method Details

.accumulated_decoratorsArray[decorator]

Decorator-style DSL (on / priority / thread / periodic / first_run) pushes entries here; the next instance-method definition consumes them (see method_added). Both this and yuuki_methods live in per-class ivars.

Returns:

  • (Array[decorator])


10
11
12
# File 'lib/yuuki/runner.rb', line 10

def self.accumulated_decorators
  @accumulated_decorators ||= []
end

.first_run(enabled: true) ⇒ void

This method returns an undefined value.

Parameters:

  • enabled: (Boolean) (defaults to: true)


43
44
45
# File 'lib/yuuki/runner.rb', line 43

def self.first_run(enabled: true)
  accumulated_decorators << [:first_run, enabled]
end

.inherited(subclass) ⇒ void

This method returns an undefined value.

yuuki_methods is a per-class ivar, so copy it on inheritance to make runner methods defined in a superclass visible from the subclass. NOTE: methods added to the superclass after the subclass is defined are not reflected.

Parameters:

  • subclass (singleton(Runner))


22
23
24
25
# File 'lib/yuuki/runner.rb', line 22

def self.inherited(subclass)
  subclass.instance_variable_set(:@yuuki_methods, yuuki_methods.dup)
  super
end

.method_added(method_name) ⇒ void

This method returns an undefined value.

Registers the method as a runner method when decorators are pending or the name is on_<tag> (which implies the tag ). Note this hook fires for ANY instance-method definition, including attr_* and private helpers, so pending decorators are consumed by whatever method comes next.

Parameters:

  • method_name (Symbol)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/yuuki/runner.rb', line 51

def self.method_added(method_name)
  return if accumulated_decorators.empty? && !method_name.start_with?('on_')

  options = {}
  options[:tags] = [method_name[3..].to_sym] if method_name.start_with?('on_')

  accumulated_decorators.each do |tag, elem|
    if tag == :tag
      options[:tags] ||= []
      options[:tags] << elem
    else
      options[tag] = elem
    end
  end
  accumulated_decorators.clear

  yuuki_methods[method_name] = options

  super
end

.on(tag) ⇒ void

This method returns an undefined value.

Parameters:

  • tag (Symbol)


27
28
29
# File 'lib/yuuki/runner.rb', line 27

def self.on(tag)
  accumulated_decorators << [:tag, tag]
end

.periodic(interval) ⇒ void

This method returns an undefined value.

Parameters:

  • interval (Numeric)


39
40
41
# File 'lib/yuuki/runner.rb', line 39

def self.periodic(interval)
  accumulated_decorators << [:periodic, interval]
end

.priority(priority = 0) ⇒ void

This method returns an undefined value.

Parameters:

  • priority (Integer) (defaults to: 0)


31
32
33
# File 'lib/yuuki/runner.rb', line 31

def self.priority(priority = 0)
  accumulated_decorators << [:priority, priority]
end

.singleton_method_added(_method_name) ⇒ void

This method returns an undefined value.

Parameters:

  • _method_name (Symbol)


72
73
74
75
# File 'lib/yuuki/runner.rb', line 72

def self.singleton_method_added(_method_name)
  accumulated_decorators.clear
  super
end

.thread(enabled: true) ⇒ void

This method returns an undefined value.

Parameters:

  • enabled: (Boolean) (defaults to: true)


35
36
37
# File 'lib/yuuki/runner.rb', line 35

def self.thread(enabled: true)
  accumulated_decorators << [:thread, enabled]
end

.yuuki_methodsHash[Symbol, meta]

Returns:

  • (Hash[Symbol, meta])


14
15
16
# File 'lib/yuuki/runner.rb', line 14

def self.yuuki_methods
  @yuuki_methods ||= {}
end