Skip to content
Snippets Groups Projects
Commit 6a3a3aa3 authored by cleemy desu wayo's avatar cleemy desu wayo
Browse files

Modify: change variable name

This commit changes variable names.

If you register a Proc without using hook, you will need a
different Hash key than before.

| old key  |  new key   |
-------------------------
|  source  |  ds_label  |
|   cond   | event_cond |
|   proc   |    proc    |
parent 369e422c
Branches main
No related tags found
No related merge requests found
#!/usr/bin/env ruby
#
# ==========================================================================
# Outvoke -- version 0.0.99.20241112.2
# Outvoke -- version 0.0.99.20241112.3
#
# written by cleemy desu wayo / Licensed under CC0 1.0
#
......@@ -25,7 +25,7 @@ class Outvoke
@version = Struct.new(:branch, :body).new(
'0.1',
'0.0.99.20241112.2'
'0.0.99.20241112.3'
)
@ds = Hash.new
......@@ -103,7 +103,7 @@ class Outvoke
def mainloop
loop do
@ds.each do |dslabel, ds|
@ds.each do |ds_label, ds|
next unless ds.enabled?
ds.before_each_event
......@@ -124,11 +124,11 @@ class Outvoke
end
# extracts only the labels of the appropriate data sources from $sources
def extract_ds(dslabel)
return @ds.keys if dslabel == true
def extract_ds(ds_cond)
return @ds.keys if ds_cond == true
label_cond_array = [dslabel]
label_cond_array = dslabel if dslabel.respond_to?(:each)
label_cond_array = [ds_cond]
label_cond_array = ds_cond if ds_cond.respond_to?(:each)
result = []
......@@ -181,27 +181,27 @@ class Outvoke
def hooks_exec(ds, event)
@hooks.each do |hook|
# check data source
next unless hook['source'] == ds.label # TODO
next unless hook['ds_label'] == ds.label
hook_cond_array = [hook['cond']]
if hook['cond'].respond_to?(:each)
hook_cond_array = hook['cond']
event_cond_array = [hook['event_cond']]
if hook['event_cond'].respond_to?(:each)
event_cond_array = hook['event_cond']
end
event.is_quiet_mode = @is_quiet_mode # TODO
# check condition
hook_cond_array.detect do |cond|
event_cond_array.detect do |event_cond|
event.m = nil
if cond == true
if event_cond == true
event.m = [event.body]
elsif cond.is_a?(String)
event.m = [event.body] if event.body.start_with?(cond)
elsif cond.respond_to?(:match)
event.m = cond.match(event.body)
elsif cond.respond_to?(:call)
proc_result = cond.call(event)
elsif event_cond.is_a?(String)
event.m = [event.body] if event.body.start_with?(event_cond)
elsif event_cond.respond_to?(:match)
event.m = event_cond.match(event.body)
elsif event_cond.respond_to?(:call)
proc_result = event_cond.call(event)
if proc_result
if proc_result.respond_to?(:each)
event.m = proc_result.each
......@@ -278,9 +278,9 @@ module OutvokeDSL
$outvoke.ds[ds_label].enabled = true
$outvoke << {
'source' => ds_label, # TODO
'cond' => event_cond,
'proc' => block
'ds_label' => ds_label,
'event_cond' => event_cond,
'proc' => block
}
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment