ehbrs-tools 0.17.0 → 0.18.0
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/lib/ehbrs/runner/telegram.rb +26 -0
- data/lib/ehbrs/runner/telegram/send_message.rb +29 -0
- data/lib/ehbrs/telegram.rb +9 -0
- data/lib/ehbrs/telegram/message_sending.rb +32 -0
- data/lib/ehbrs/tools/instance.rb +16 -0
- data/lib/ehbrs/tools/version.rb +1 -1
- data/vendor/eac_cli/lib/eac_cli/docopt/runner_context_replacement.rb +15 -0
- data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +5 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +4 -4
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/long_options.rb +37 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/option_argument.rb +29 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +7 -36
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/short_options.rb +45 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +14 -2
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +22 -1
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner/test_all.rb +4 -9
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/traverser.rb +0 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb +4 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/local_time_zone.rb +38 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/kernel.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/kernel/nyi.rb +8 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/default_time_zone_set.rb +3 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/inflector_spec.rb +2 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/local_time_zone_spec.rb +17 -0
- metadata +29 -3
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebaf532c7759e39fe14d8ce5e9af873701dfe9aa08dfd8ab23ee2c7e85fbac74
|
4
|
+
data.tar.gz: f2626b4eb360505865394303512f6871a20b14d47d62b1910aa22022abf0f03e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf01879a8df667ffd0f2be51565ddf928351444a1d0504154e8503c6f655ee5e324ac19f705e7510f74b87c1b626d6bfb52482a7a447361fd4bca51acd9f4905
|
7
|
+
data.tar.gz: abaa72ab5d0cc2c448655ad017541a467aad4eac206bd1d75707ea027c82043dc0401ffcb8993a6e765b728e3aa3d6ef4fd9fafb735ae6c41e749095458da1a5
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/core_ext'
|
4
|
+
require 'ehbrs/tools/instance'
|
5
|
+
|
6
|
+
module Ehbrs
|
7
|
+
class Runner
|
8
|
+
class Telegram
|
9
|
+
require_sub __FILE__
|
10
|
+
|
11
|
+
runner_with :help, :subcommands do
|
12
|
+
desc 'Operações com Telegram.'
|
13
|
+
arg_opt '-b', '--bot-token', 'Token do bot Telegram.'
|
14
|
+
subcommands
|
15
|
+
end
|
16
|
+
|
17
|
+
def bot_token
|
18
|
+
parsed.bot_token || default_bot_token
|
19
|
+
end
|
20
|
+
|
21
|
+
def default_bot_token
|
22
|
+
::Ehbrs::Tools.instance.read_entry(:telegram_bot_token)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/core_ext'
|
4
|
+
require 'ehbrs/telegram/message_sending'
|
5
|
+
|
6
|
+
module Ehbrs
|
7
|
+
class Runner
|
8
|
+
class Telegram
|
9
|
+
class SendMessage
|
10
|
+
runner_with :help do
|
11
|
+
desc 'Envia mensagens Telegram.'
|
12
|
+
pos_arg :message
|
13
|
+
pos_arg :recipients_ids, repeat: true
|
14
|
+
end
|
15
|
+
|
16
|
+
delegate :run, to: :message_sending
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def message_sending_uncached
|
21
|
+
parsed.recipients_ids
|
22
|
+
.inject(::Ehbrs::Telegram::MessageSending.new) { |a, e| a.recipient_id(e) }
|
23
|
+
.bot_token(runner_context.call(:bot_token))
|
24
|
+
.message(parsed.message)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_ruby_utils/immutable'
|
5
|
+
require 'telegram/bot'
|
6
|
+
|
7
|
+
module Ehbrs
|
8
|
+
module Telegram
|
9
|
+
class MessageSending
|
10
|
+
include ::EacRubyUtils::Immutable
|
11
|
+
immutable_accessor :bot_token, :message
|
12
|
+
immutable_accessor :recipient_id, type: :array
|
13
|
+
|
14
|
+
def run
|
15
|
+
::Telegram::Bot::Client.run(prop(:bot_token)) do |bot|
|
16
|
+
prop(:recipient_ids).each do |recipient_id|
|
17
|
+
bot.api.sendMessage(chat_id: recipient_id, text: prop(:message))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def prop(attribute)
|
25
|
+
r = send(attribute)
|
26
|
+
return r if r.present?
|
27
|
+
|
28
|
+
raise "Attribute #{attribute} is blank"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/instances/base'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
|
6
|
+
module Ehbrs
|
7
|
+
module Tools
|
8
|
+
INSTANCE_ID = 'ehbrs-tools_0'
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def instance
|
12
|
+
@instance ||= ::Avm::Instances::Base.by_id(INSTANCE_ID)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/ehbrs/tools/version.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'eac_cli/docopt/doc_builder'
|
4
|
+
require 'eac_cli/docopt/runner_context_replacement'
|
4
5
|
require 'eac_cli/runner'
|
5
6
|
require 'eac_ruby_utils/console/docopt_runner'
|
6
7
|
|
@@ -32,6 +33,10 @@ module EacCli
|
|
32
33
|
def docopt_options
|
33
34
|
super.merge(options_first: self.class.runner_definition.options_first?)
|
34
35
|
end
|
36
|
+
|
37
|
+
def runner_context
|
38
|
+
@runner_context ||= ::EacCli::Docopt::RunnerContextReplacement.new(self)
|
39
|
+
end
|
35
40
|
end
|
36
41
|
|
37
42
|
def extra_available_subcommands
|
@@ -35,11 +35,11 @@ module EacCli
|
|
35
35
|
attr_accessor :phase
|
36
36
|
|
37
37
|
def any_collect_argv_value
|
38
|
-
|
39
|
-
|
40
|
-
else
|
41
|
-
positional_collect_argv_value
|
38
|
+
%w[double_dash long_option short_option].each do |arg_type|
|
39
|
+
return send("#{arg_type}_collect_argv_value") if send("argv_current_#{arg_type}?")
|
42
40
|
end
|
41
|
+
|
42
|
+
positional_collect_argv_value
|
43
43
|
end
|
44
44
|
|
45
45
|
def collector
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class Parser
|
5
|
+
class Alternative
|
6
|
+
module LongOptions
|
7
|
+
LONG_OPTION_PREFIX = '--'
|
8
|
+
OPTION_WITH_ARGUMENT_PATTERN = /\A([^=]+)(?:=(.*))\z/.freeze
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def argv_current_long_option?
|
13
|
+
phase == PHASE_ANY && argv_enum.peek.start_with?(LONG_OPTION_PREFIX) &&
|
14
|
+
!argv_current_double_dash?
|
15
|
+
end
|
16
|
+
|
17
|
+
def long_option_collect_argv_value
|
18
|
+
option_long, value = parse_option_current_argv
|
19
|
+
alternative.options.any? do |option|
|
20
|
+
next false unless option.long == option_long
|
21
|
+
|
22
|
+
if value.nil?
|
23
|
+
option_collect_option(option)
|
24
|
+
else
|
25
|
+
option_argument_collect(option, value)
|
26
|
+
end
|
27
|
+
end || raise_argv_current_invalid_option
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_option_current_argv
|
31
|
+
m = OPTION_WITH_ARGUMENT_PATTERN.match(argv_enum.peek)
|
32
|
+
m ? [m[1], m[2].if_present('')] : [argv_enum.peek, nil]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class Parser
|
5
|
+
class Alternative
|
6
|
+
module OptionArgument
|
7
|
+
private
|
8
|
+
|
9
|
+
attr_accessor :argument_option
|
10
|
+
|
11
|
+
def argument_option_collect_argv(option)
|
12
|
+
self.argument_option = option
|
13
|
+
self.phase = PHASE_OPTION_ARGUMENT
|
14
|
+
end
|
15
|
+
|
16
|
+
def option_argument_collect(option, value)
|
17
|
+
collector.collect(option, value)
|
18
|
+
self.argument_option = nil
|
19
|
+
self.phase = PHASE_ANY
|
20
|
+
option
|
21
|
+
end
|
22
|
+
|
23
|
+
def option_argument_collect_argv_value
|
24
|
+
option_argument_collect(argument_option, argv_enum.peek)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -4,49 +4,20 @@ module EacCli
|
|
4
4
|
class Parser
|
5
5
|
class Alternative
|
6
6
|
module Options
|
7
|
-
DOUBLE_DASH = '--'
|
8
|
-
|
9
7
|
private
|
10
8
|
|
11
|
-
attr_accessor :argument_option, :double_dash
|
12
|
-
|
13
|
-
def argument_option_collect_argv(option)
|
14
|
-
self.argument_option = option
|
15
|
-
self.phase = PHASE_OPTION_ARGUMENT
|
16
|
-
end
|
17
|
-
|
18
|
-
def argv_current_option?
|
19
|
-
phase == PHASE_ANY && argv_enum.peek.start_with?('-')
|
20
|
-
end
|
21
|
-
|
22
|
-
def argv_current_double_dash?
|
23
|
-
argv_enum.peek == DOUBLE_DASH && !double_dash
|
24
|
-
end
|
25
|
-
|
26
9
|
def boolean_option_collect_argv(option)
|
27
10
|
collector.collect(option, true)
|
28
11
|
end
|
29
12
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
def option_collect_argv_value
|
37
|
-
return double_dash_collect_argv_value if argv_current_double_dash?
|
38
|
-
|
39
|
-
alternative.options.any? do |option|
|
40
|
-
next false unless [option.short, option.long].include?(argv_enum.peek)
|
41
|
-
|
42
|
-
if option.argument?
|
43
|
-
argument_option_collect_argv(option)
|
44
|
-
else
|
45
|
-
boolean_option_collect_argv(option)
|
46
|
-
end
|
13
|
+
def option_collect_option(option)
|
14
|
+
if option.argument?
|
15
|
+
argument_option_collect_argv(option)
|
16
|
+
else
|
17
|
+
boolean_option_collect_argv(option)
|
18
|
+
end
|
47
19
|
|
48
|
-
|
49
|
-
end || raise_argv_current_invalid_option
|
20
|
+
option
|
50
21
|
end
|
51
22
|
|
52
23
|
def raise_argv_current_invalid_option
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class Parser
|
5
|
+
class Alternative
|
6
|
+
module ShortOptions
|
7
|
+
SHORT_OPTION_PREFIX = '-'
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def argv_current_short_option?
|
12
|
+
phase == PHASE_ANY && argv_enum.peek.start_with?(SHORT_OPTION_PREFIX) &&
|
13
|
+
!argv_current_long_option?
|
14
|
+
end
|
15
|
+
|
16
|
+
def find_short_option(char)
|
17
|
+
alternative.options.find { |option| short_without_prefix(option.short) == char }
|
18
|
+
end
|
19
|
+
|
20
|
+
def short_option_collect_argv_value
|
21
|
+
last_option = nil
|
22
|
+
short_without_prefix(argv_enum.peek).each_char do |char|
|
23
|
+
raise_error "Option \"#{last_option}\" requires a argument not provided" if
|
24
|
+
last_option.present?
|
25
|
+
|
26
|
+
collected_option = short_option_collect_char(char)
|
27
|
+
last_option = collected_option if collected_option.argument?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [EacCli::Definition::BaseOption] The option collected.
|
32
|
+
def short_option_collect_char(char)
|
33
|
+
option = find_short_option(char)
|
34
|
+
raise_error "Invalid short option \"#{char}\"" unless option
|
35
|
+
|
36
|
+
option_collect_option(option)
|
37
|
+
end
|
38
|
+
|
39
|
+
def short_without_prefix(short)
|
40
|
+
short.gsub(/\A#{::Regexp.quote(SHORT_OPTION_PREFIX)}/, '')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -6,6 +6,14 @@ require 'eac_ruby_utils/core_ext'
|
|
6
6
|
module EacCli
|
7
7
|
module RunnerWith
|
8
8
|
module Subcommands
|
9
|
+
class << self
|
10
|
+
def runner?(object)
|
11
|
+
::EacCli::Runner.runner?(object) || (
|
12
|
+
object.is_a?(::Class) && object < ::EacRubyUtils::Console::DocoptRunner
|
13
|
+
)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
9
17
|
common_concern do
|
10
18
|
include ::EacCli::Runner
|
11
19
|
end
|
@@ -19,7 +27,7 @@ module EacCli
|
|
19
27
|
def available_subcommands_auto
|
20
28
|
self.class.constants
|
21
29
|
.map { |name| [name.to_s.underscore.gsub('_', '-'), self.class.const_get(name)] }
|
22
|
-
.select { |c| ::EacCli::
|
30
|
+
.select { |c| ::EacCli::RunnerWith::Subcommands.runner?(c[1]) }
|
23
31
|
.to_h.with_indifferent_access
|
24
32
|
end
|
25
33
|
|
@@ -49,7 +57,11 @@ module EacCli
|
|
49
57
|
|
50
58
|
def run_with_subcommand
|
51
59
|
if subcommand_name
|
52
|
-
subcommand_runner.run_run
|
60
|
+
if subcommand_runner.respond_to?(:run_run)
|
61
|
+
subcommand_runner.run_run
|
62
|
+
else
|
63
|
+
subcommand_runner.run
|
64
|
+
end
|
53
65
|
else
|
54
66
|
run_without_subcommand
|
55
67
|
end
|
@@ -11,7 +11,7 @@ RSpec.describe ::EacCli::Runner do
|
|
11
11
|
|
12
12
|
runner_definition do
|
13
13
|
arg_opt '-o', '--opt1', 'A arg option.'
|
14
|
-
bool_opt '-
|
14
|
+
bool_opt '-p', '--opt2', 'A boolean option'
|
15
15
|
pos_arg :pos1
|
16
16
|
pos_arg :pos2, repeat: true, optional: true
|
17
17
|
alt do
|
@@ -40,6 +40,27 @@ RSpec.describe ::EacCli::Runner do
|
|
40
40
|
it { expect(instance.parsed.pos2).to eq(%w[ccc ddd]) }
|
41
41
|
end
|
42
42
|
|
43
|
+
context 'with long option and argument in same position' do
|
44
|
+
let(:argv) { %w[--opt1=aaa pos1] }
|
45
|
+
|
46
|
+
it { expect(instance.parsed.opt1).to eq('aaa') }
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'with valid grouped short options' do
|
50
|
+
let(:argv) { %w[-po aaa pos1] }
|
51
|
+
|
52
|
+
it { expect(instance.parsed.opt1).to eq('aaa') }
|
53
|
+
it { expect(instance.parsed.opt2?).to eq(true) }
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'with invalid grouped short options' do
|
57
|
+
let(:argv) { %w[-op aaa pos1] }
|
58
|
+
|
59
|
+
it do
|
60
|
+
expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
43
64
|
context 'when only required args are supplied' do
|
44
65
|
let(:argv) { %w[bbb] }
|
45
66
|
let(:parsed_expected) { { opt1: nil, opt2: false, opt3: false, pos1: 'bbb', pos2: [] } }
|
@@ -1,17 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'eac_cli/
|
4
|
-
require 'eac_ruby_utils/console/docopt_runner'
|
5
|
-
require 'eac_ruby_utils/core_ext'
|
3
|
+
require 'eac_cli/core_ext'
|
6
4
|
require 'eac_ruby_gems_utils/tests/multiple'
|
7
5
|
|
8
6
|
module EacRubyBase0
|
9
7
|
module Runner
|
10
|
-
class TestAll
|
11
|
-
|
12
|
-
include ::EacCli::DefaultRunner
|
13
|
-
|
14
|
-
runner_definition do
|
8
|
+
class TestAll
|
9
|
+
runner_with :help do
|
15
10
|
desc 'Test core and local gems.'
|
16
11
|
end
|
17
12
|
|
@@ -20,7 +15,7 @@ module EacRubyBase0
|
|
20
15
|
end
|
21
16
|
|
22
17
|
def tests_uncached
|
23
|
-
::EacRubyGemsUtils::Tests::Multiple.new(
|
18
|
+
::EacRubyGemsUtils::Tests::Multiple.new(runner_context.call(:application).all_gems)
|
24
19
|
end
|
25
20
|
end
|
26
21
|
end
|
@@ -1,12 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'active_support/inflector'
|
4
|
+
|
3
5
|
module EacRubyUtils
|
4
6
|
class Inflector
|
5
7
|
class << self
|
6
8
|
VARIABLE_NAME_PATTERN = /[_a-z][_a-z0-9]*/i.freeze
|
7
9
|
|
8
10
|
def variableize(string)
|
9
|
-
r = string.gsub(/[^_a-z0-9]/i, '_')
|
11
|
+
r = ::ActiveSupport::Inflector.transliterate(string).gsub(/[^_a-z0-9]/i, '_')
|
12
|
+
.gsub(/_+/, '_').gsub(/_\z/, '').gsub(/\A_/, '').downcase
|
10
13
|
m = VARIABLE_NAME_PATTERN.match(r)
|
11
14
|
return r if m
|
12
15
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/object/blank'
|
4
|
+
require 'active_support/values/time_zone'
|
5
|
+
|
6
|
+
module EacRubyUtils
|
7
|
+
module LocalTimeZone
|
8
|
+
DEBIAN_CONFIG_PATH = '/etc/timezone'
|
9
|
+
|
10
|
+
class << self
|
11
|
+
TIMEDATECTL_TIMEZONE_LINE_PATTERN = %r{\s*Time zone:\s*(\S+/\S+)\s}.freeze
|
12
|
+
|
13
|
+
def auto
|
14
|
+
%w[tz_env debian_config offset].lazy.map { |s| send("by_#{s}") }.find(&:present?)
|
15
|
+
end
|
16
|
+
|
17
|
+
def by_debian_config
|
18
|
+
path = ::Pathname.new(DEBIAN_CONFIG_PATH)
|
19
|
+
path.exist? ? path.read.strip.presence : nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def by_offset
|
23
|
+
::ActiveSupport::TimeZone[::Time.now.getlocal.gmt_offset].name
|
24
|
+
end
|
25
|
+
|
26
|
+
def by_timedatectl
|
27
|
+
executable = ::EacRubyUtils::Envs.local.executable('timedatectl', '--version')
|
28
|
+
return nil unless executable.exist?
|
29
|
+
|
30
|
+
TIMEDATECTL_TIMEZONE_LINE_PATTERN.if_match(executable.command.execute!) { |m| m[1] }
|
31
|
+
end
|
32
|
+
|
33
|
+
def by_tz_env
|
34
|
+
ENV['TZ'].presence
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'active_support/core_ext/time/zones'
|
4
|
+
require 'eac_ruby_utils/local_time_zone'
|
4
5
|
|
5
|
-
::Time.zone = ::
|
6
|
+
::Time.zone = ::EacRubyUtils::LocalTimeZone.auto
|
@@ -5,7 +5,8 @@ require 'eac_ruby_utils/inflector'
|
|
5
5
|
RSpec.describe ::EacRubyUtils::Inflector do
|
6
6
|
describe '#variableize' do
|
7
7
|
{
|
8
|
-
'_A_variableName' => 'a_variablename'
|
8
|
+
'_A_variableName' => 'a_variablename',
|
9
|
+
'àéíöũ' => 'aeiou'
|
9
10
|
}.each do |source, expected|
|
10
11
|
context "when source is \"#{source}\"" do
|
11
12
|
it { expect(described_class.variableize(source)).to eq(expected) }
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/local_time_zone'
|
4
|
+
|
5
|
+
RSpec.describe(::EacRubyUtils::LocalTimeZone) do
|
6
|
+
describe '#auto' do
|
7
|
+
context 'when TZ environment variable is set' do
|
8
|
+
let(:expected_time_zone) { 'America/Sao_Paulo' }
|
9
|
+
|
10
|
+
before do
|
11
|
+
ENV['TZ'] = expected_time_zone
|
12
|
+
end
|
13
|
+
|
14
|
+
it { expect(described_class.auto).to eq(expected_time_zone) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ehbrs-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avm-tools
|
@@ -92,6 +92,20 @@ dependencies:
|
|
92
92
|
- - "~>"
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '3.0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: telegram-bot-ruby
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
95
109
|
- !ruby/object:Gem::Dependency
|
96
110
|
name: eac_ruby_gem_support
|
97
111
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,6 +164,8 @@ files:
|
|
150
164
|
- lib/ehbrs/runner/google/translate.rb
|
151
165
|
- lib/ehbrs/runner/self.rb
|
152
166
|
- lib/ehbrs/runner/self/test.rb
|
167
|
+
- lib/ehbrs/runner/telegram.rb
|
168
|
+
- lib/ehbrs/runner/telegram/send_message.rb
|
153
169
|
- lib/ehbrs/runner/vg.rb
|
154
170
|
- lib/ehbrs/runner/vg/ips.rb
|
155
171
|
- lib/ehbrs/runner/vg/wii.rb
|
@@ -166,8 +182,11 @@ files:
|
|
166
182
|
- lib/ehbrs/self.rb
|
167
183
|
- lib/ehbrs/self/observers/used_space.rb
|
168
184
|
- lib/ehbrs/self/observers/with_persistence.rb
|
185
|
+
- lib/ehbrs/telegram.rb
|
186
|
+
- lib/ehbrs/telegram/message_sending.rb
|
169
187
|
- lib/ehbrs/tools.rb
|
170
188
|
- lib/ehbrs/tools/application.rb
|
189
|
+
- lib/ehbrs/tools/instance.rb
|
171
190
|
- lib/ehbrs/tools/version.rb
|
172
191
|
- lib/ehbrs/user_dirs.rb
|
173
192
|
- lib/ehbrs/vg.rb
|
@@ -279,13 +298,17 @@ files:
|
|
279
298
|
- vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
|
280
299
|
- vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb
|
281
300
|
- vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb
|
301
|
+
- vendor/eac_cli/lib/eac_cli/docopt/runner_context_replacement.rb
|
282
302
|
- vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb
|
283
303
|
- vendor/eac_cli/lib/eac_cli/parser.rb
|
284
304
|
- vendor/eac_cli/lib/eac_cli/parser/alternative.rb
|
285
305
|
- vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb
|
286
306
|
- vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb
|
307
|
+
- vendor/eac_cli/lib/eac_cli/parser/alternative/long_options.rb
|
308
|
+
- vendor/eac_cli/lib/eac_cli/parser/alternative/option_argument.rb
|
287
309
|
- vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb
|
288
310
|
- vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb
|
311
|
+
- vendor/eac_cli/lib/eac_cli/parser/alternative/short_options.rb
|
289
312
|
- vendor/eac_cli/lib/eac_cli/parser/collector.rb
|
290
313
|
- vendor/eac_cli/lib/eac_cli/parser/error.rb
|
291
314
|
- vendor/eac_cli/lib/eac_cli/patches.rb
|
@@ -420,6 +443,7 @@ files:
|
|
420
443
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/string_list.rb
|
421
444
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/symbol_list.rb
|
422
445
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/value.rb
|
446
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/local_time_zone.rb
|
423
447
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/on_clean_ruby_environment.rb
|
424
448
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/options_consumer.rb
|
425
449
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patch.rb
|
@@ -434,6 +458,8 @@ files:
|
|
434
458
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash.rb
|
435
459
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/options_consumer.rb
|
436
460
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/sym_keys_hash.rb
|
461
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/kernel.rb
|
462
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/kernel/nyi.rb
|
437
463
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module.rb
|
438
464
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb
|
439
465
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/common_concern.rb
|
@@ -459,7 +485,6 @@ files:
|
|
459
485
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string/inflector.rb
|
460
486
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time.rb
|
461
487
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/default_time_zone_set.rb
|
462
|
-
- vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb
|
463
488
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb
|
464
489
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/entry_key_error.rb
|
465
490
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/node.rb
|
@@ -504,6 +529,7 @@ files:
|
|
504
529
|
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/temp_spec.rb
|
505
530
|
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/inflector_spec.rb
|
506
531
|
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/listable_spec.rb
|
532
|
+
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/local_time_zone_spec.rb
|
507
533
|
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb
|
508
534
|
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerable/boolean_combinations_spec.rb
|
509
535
|
- vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/current_spec.rb
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'active_support/core_ext/time/zones'
|
4
|
-
require 'eac_ruby_utils/envs'
|
5
|
-
|
6
|
-
class Time
|
7
|
-
class << self
|
8
|
-
TIMEDATECTL_TIMEZONE_LINE_PATTERN = %r{\s*Time zone:\s*(\S+/\S+)\s}.freeze
|
9
|
-
|
10
|
-
def local_time_zone
|
11
|
-
local_time_zone_by_timedatectl || local_time_zone_by_offset
|
12
|
-
end
|
13
|
-
|
14
|
-
def local_time_zone_by_timedatectl
|
15
|
-
executable = ::EacRubyUtils::Envs.local.executable('timedatectl', '--version')
|
16
|
-
return nil unless executable.exist?
|
17
|
-
|
18
|
-
TIMEDATECTL_TIMEZONE_LINE_PATTERN.if_match(executable.command.execute!) { |m| m[1] }
|
19
|
-
end
|
20
|
-
|
21
|
-
def local_time_zone_by_offset
|
22
|
-
::ActiveSupport::TimeZone[::Time.now.getlocal.gmt_offset].name
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|