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

Modify: remove feature "ignore_list"

This commit removes a feature "ignore_list". Use new feature
"nodup" instead of "ignore_list".

With this change, any value returned by a Proc registered by hook
that is not true, false, nil, etc. will now be converted to a
string and output.

----
$ seq 1 3 | ./outvoke.rb -q -e 'hook("stdin") { _1.body.to_i * 2 }'
2
4
6
----
parent c61c4312
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env ruby
#
# ==========================================================================
# Outvoke -- version 0.0.99.20241110
# Outvoke -- version 0.0.99.20241110.1
#
# written by cleemy desu wayo / Licensed under CC0 1.0
#
......@@ -23,7 +23,7 @@ class Outvoke
@version = Struct.new(:branch, :body).new(
'0.1',
'0.0.99.20241110'
'0.0.99.20241110.1'
)
@sources = Hash.new
......@@ -218,35 +218,19 @@ class Outvoke
hook_result = tmp_context.instance_exec(event, &hook['proc'])
end
is_log_outputted = false
if hook_result.is_a?(String)
if not @is_quiet_mode
puts "[#{event.time}] #{hook_result}".gsub("\n", " ")
else
puts hook_result
end
is_log_outputted = true
elsif hook_result.is_a?(Hash)
if hook_result['log']
if not @is_quiet_mode
puts "[#{event.time}] #{hook_result['log']}".gsub("\n", " ")
else
puts hook_result['log']
end
is_log_outputted = true
end
if hook_result['ignore']
event.status.ignore_list[hook_result['ignore'][0]] = [event.time, hook_result['ignore'][1]]
end
hook_result_for_post_process = nil
if hook_result == true
hook_result_for_post_process = event.body
elsif (hook_result != nil && hook_result != false)
hook_result_for_post_process = hook_result
end
if not is_log_outputted
if (not hook['proc']) || (hook['proc'] && hook_result)
if not @is_quiet_mode
puts "[#{event.time}] #{event.body}".gsub("\n", " ")
else
puts event.body
end
if hook_result_for_post_process
if not @is_quiet_mode
puts "[#{event.time}] #{hook_result_for_post_process}".gsub("\n", " ")
else
puts hook_result_for_post_process.to_s
end
end
end
......@@ -345,30 +329,6 @@ module OutvokeDSL
$outvoke.nodup?(x)
end
#
# *** NOTE ***
# this feature may be removed in the future. use new feature "nodup".
#
def ignore?(dslabel, value, sec)
raise '$outvoke is not an Outvoke object' unless $outvoke.is_a?(Outvoke)
is_empty = false
ignore_limit = nil
if not $outvoke.sources[dslabel].status.ignore_list[value]
is_empty = true
$outvoke.sources[dslabel].status.ignore_list[value] = []
else
ignore_limit = $outvoke.sources[dslabel].status.ignore_list[value][0] +
$outvoke.sources[dslabel].status.ignore_list[value][1]
end
$outvoke.sources[dslabel].status.ignore_list[value][0] = Time.now
$outvoke.sources[dslabel].status.ignore_list[value][1] = sec
return false if is_empty
#p "ignore_limit: #{ignore_limit} ---- now: #{Time.now}" # DEBUG
return ignore_limit > Time.now
end
end
#
......@@ -563,7 +523,7 @@ class OutvokeDataSourceLoopback < OutvokeDataSource
end
StructDSVrchatStatus = Struct.new(:now, :logfile, :file_size,
:last_joined_time, :elapsed, :ignore_list, :count, :lineno)
:last_joined_time, :elapsed, :count, :lineno)
StructDSVrchatEvent = Struct.new(:status, :raw, :time, :type, :body, :m)
class OutvokeDataSourceVrchat < OutvokeDataSource
......@@ -575,7 +535,6 @@ class OutvokeDataSourceVrchat < OutvokeDataSource
@status = StructDSVrchatStatus.new
@status.logfile = nil
@status.file_size = 0
@status.ignore_list = Hash.new
@status.count = 0
@status.lineno = 0
@log_dir = ''
......
# for Outvoke 0.1
# written by cleemy desu wayo / Licensed under CC0 1.0
# initial release of this sample: 2024-11-10
# --------
#
# this sample code is for checking the changes in version 0.0.99.20241110.1
#
# usage:
#
# $ seq 1 10 | ./outvoke.rb samples/2024/modify_20241110.1_remove_ignore.rb
#
using OutvokeDSL
hook "stdin", /\A1\z/ do |e|
puts "puts e.body ---- #{e.body}"
true
end
hook "stdin", /\A2\z/ do |e|
puts "puts e.body ---- #{e.body}"
"true"
end
hook "stdin", /\A3\z/ do |e|
puts "puts e.body ---- #{e.body}"
false
end
hook "stdin", /\A4\z/ do |e|
puts "puts e.body ---- #{e.body}"
nil
end
hook "stdin", /\A5\z/ do |e|
puts "puts e.body ---- #{e.body}"
1
end
hook "stdin", /\A6\z/ do |e|
puts "puts e.body ---- #{e.body}"
{"log" => "hello"}
end
hook "stdin", /\A7\z/ do |e|
puts "puts e.body ---- #{e.body}"
{"log_" => "hello"}
end
hook "stdin", /\A8\z/ do |e|
puts "puts e.body ---- #{e.body}"
e.body * 2
end
hook "stdin", /\A9\z/ do |e|
puts "puts e.body ---- #{e.body}"
e.body.to_i * 2
end
hook "stdin", /\A10\z/ do |e|
puts "puts e.body ---- #{e.body}"
[e.body.to_i * 2]
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