eac_ruby_utils 0.44.0 → 0.47.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eac_ruby_utils/common_concern.rb +4 -4
- data/lib/eac_ruby_utils/console/docopt_runner.rb +6 -0
- data/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +1 -1
- data/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +8 -2
- data/lib/eac_ruby_utils/inflector.rb +18 -0
- data/lib/eac_ruby_utils/listable/value.rb +3 -2
- data/lib/eac_ruby_utils/patches/string.rb +4 -0
- data/lib/eac_ruby_utils/patches/string/inflector.rb +9 -0
- data/lib/eac_ruby_utils/ruby/command.rb +2 -1
- data/lib/eac_ruby_utils/simple_cache.rb +6 -2
- data/lib/eac_ruby_utils/struct.rb +53 -0
- data/lib/eac_ruby_utils/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdfe776f80d9f9d2326f040cc996e8b2dc5a08aaf7cb8eccf0a3ebb3b6d2ab4d
|
4
|
+
data.tar.gz: 4b0b779ca185c887ee7204050428060a115d12392f1807017a2dd16beec934ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9eace3e6ff7bdab20d791e9d7e5bfe81f9f8bd6ca93fb815bb77d63d30a0c2d1604ee4e3bfecbe892b179dc7c557ee9b1554a26281ba003326c12fc50c2f9ce3
|
7
|
+
data.tar.gz: 5ea6a75da16e45cf51e4610dbe7f0fd51ec4ccc7a7e52f96f0f5590be168d5fa6d7a1d95e95e890e10c36736b33dc2323b2549f5e8c1caf21c4af47a27e59ba5
|
@@ -21,10 +21,10 @@ module EacRubyUtils
|
|
21
21
|
|
22
22
|
class Setup
|
23
23
|
include ::EacRubyUtils::SimpleCache
|
24
|
-
attr_reader :a_module, :
|
24
|
+
attr_reader :a_module, :common_concern
|
25
25
|
|
26
|
-
def initialize(
|
27
|
-
@
|
26
|
+
def initialize(common_concern, a_module)
|
27
|
+
@common_concern = common_concern
|
28
28
|
@a_module = a_module
|
29
29
|
end
|
30
30
|
|
@@ -47,7 +47,7 @@ module EacRubyUtils
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def setup_after_callback(base)
|
50
|
-
|
50
|
+
common_concern.after_callback.if_present do |v|
|
51
51
|
base.instance_eval(&v)
|
52
52
|
end
|
53
53
|
end
|
@@ -25,6 +25,8 @@ module EacRubyUtils
|
|
25
25
|
end
|
26
26
|
|
27
27
|
module SubcommandsSupport
|
28
|
+
EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME = :extra_available_subcommands
|
29
|
+
|
28
30
|
def check_subcommands_arg
|
29
31
|
if subcommand_arg_as_list?
|
30
32
|
singleton_class.include(SubcommandsSupport::SubcommandArgAsList)
|
@@ -43,7 +45,7 @@ module EacRubyUtils
|
|
43
45
|
end
|
44
46
|
|
45
47
|
def subcommand
|
46
|
-
@subcommand ||= subcommand_class_name(subcommand_name).constantize.
|
48
|
+
@subcommand ||= subcommand_class_name(subcommand_name).constantize.create(
|
47
49
|
argv: subcommand_args,
|
48
50
|
program_name: subcommand_program,
|
49
51
|
parent: self
|
@@ -77,7 +79,11 @@ module EacRubyUtils
|
|
77
79
|
end
|
78
80
|
|
79
81
|
def available_subcommands
|
80
|
-
(setting_value(:subcommands, false) || auto_available_subcommands)
|
82
|
+
r = ::Set.new(setting_value(:subcommands, false) || auto_available_subcommands)
|
83
|
+
if respond_to?(EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME, true)
|
84
|
+
r += send(EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME)
|
85
|
+
end
|
86
|
+
r.sort
|
81
87
|
end
|
82
88
|
|
83
89
|
def auto_available_subcommands
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
class Inflector
|
5
|
+
class << self
|
6
|
+
VARIABLE_NAME_PATTERN = /[_a-z][_a-z0-9]*/i.freeze
|
7
|
+
|
8
|
+
def variableize(string)
|
9
|
+
r = string.gsub(/[^_a-z0-9]/i, '_').gsub(/_+/, '_').gsub(/_\z/, '').gsub(/\A_/, '').downcase
|
10
|
+
m = VARIABLE_NAME_PATTERN.match(r)
|
11
|
+
return r if m
|
12
|
+
|
13
|
+
raise ::ArgumentError, "Invalid variable name \"#{r}\" was generated " \
|
14
|
+
"from string \"#{string}\""
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_ruby_utils/inflector'
|
4
|
+
|
3
5
|
module EacRubyUtils
|
4
6
|
module Listable
|
5
7
|
class Value
|
@@ -16,8 +18,7 @@ module EacRubyUtils
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def constant_name
|
19
|
-
"#{@list.item}_#{@key}"
|
20
|
-
.gsub(/(?:\A_|_\z)/, '').upcase
|
21
|
+
::EacRubyUtils::Inflector.variableize("#{@list.item}_#{@key}").upcase
|
21
22
|
end
|
22
23
|
|
23
24
|
def label
|
@@ -8,7 +8,8 @@ module EacRubyUtils
|
|
8
8
|
# A [EacRubyUtils::Envs::Command] which runs in a clean Ruby environment.
|
9
9
|
class Command < ::EacRubyUtils::Envs::Command
|
10
10
|
def initialize(bundle_args, extra_options = {})
|
11
|
-
|
11
|
+
host_env = extra_options.delete(:host_env)
|
12
|
+
super(host_env || ::EacRubyUtils::Envs.local, bundle_args, extra_options)
|
12
13
|
end
|
13
14
|
|
14
15
|
%w[system execute].each do |method_prefix|
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/hash_with_indifferent_access'
|
4
|
+
require 'active_support/core_ext/object/blank'
|
5
|
+
|
6
|
+
module EacRubyUtils
|
7
|
+
class Struct
|
8
|
+
def initialize(initial_data = {})
|
9
|
+
self.data = ::ActiveSupport::HashWithIndifferentAccess.new(initial_data)
|
10
|
+
end
|
11
|
+
|
12
|
+
def [](key)
|
13
|
+
key, bool = parse_key(key)
|
14
|
+
bool ? self[key].present? : data[key]
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch(key)
|
18
|
+
key, bool = parse_key(key)
|
19
|
+
bool ? fetch(key).present? : data.fetch(key)
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_missing(method_name, *arguments, &block)
|
23
|
+
property_method?(method_name) ? fetch(method_name) : super
|
24
|
+
end
|
25
|
+
|
26
|
+
def respond_to_missing?(method_name, include_private = false)
|
27
|
+
property_method?(method_name) || super
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_h
|
31
|
+
data.dup
|
32
|
+
end
|
33
|
+
|
34
|
+
delegate :to_s, to: :data
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_accessor :data
|
39
|
+
|
40
|
+
def parse_key(key)
|
41
|
+
m = /\A(.+)\?\z/.match(key.to_s)
|
42
|
+
[(m ? m[1] : key.to_s).to_sym, m ? true : false]
|
43
|
+
end
|
44
|
+
|
45
|
+
def property_method?(key)
|
46
|
+
property_methods.include?(key.to_sym)
|
47
|
+
end
|
48
|
+
|
49
|
+
def property_methods
|
50
|
+
data.keys.flat_map { |k| [k.to_sym, "#{k}?".to_sym] }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac_ruby_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.47.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -161,6 +161,7 @@ files:
|
|
161
161
|
- lib/eac_ruby_utils/immutable/common_accessor.rb
|
162
162
|
- lib/eac_ruby_utils/immutable/hash_accessor.rb
|
163
163
|
- lib/eac_ruby_utils/immutable/instance_methods.rb
|
164
|
+
- lib/eac_ruby_utils/inflector.rb
|
164
165
|
- lib/eac_ruby_utils/listable.rb
|
165
166
|
- lib/eac_ruby_utils/listable/class_methods.rb
|
166
167
|
- lib/eac_ruby_utils/listable/instance_methods.rb
|
@@ -199,6 +200,8 @@ files:
|
|
199
200
|
- lib/eac_ruby_utils/patches/pathname/basename_sub.rb
|
200
201
|
- lib/eac_ruby_utils/patches/regexp.rb
|
201
202
|
- lib/eac_ruby_utils/patches/regexp/if_match.rb
|
203
|
+
- lib/eac_ruby_utils/patches/string.rb
|
204
|
+
- lib/eac_ruby_utils/patches/string/inflector.rb
|
202
205
|
- lib/eac_ruby_utils/patches/time.rb
|
203
206
|
- lib/eac_ruby_utils/patches/time/default_time_zone_set.rb
|
204
207
|
- lib/eac_ruby_utils/patches/time/local_time_zone.rb
|
@@ -212,6 +215,7 @@ files:
|
|
212
215
|
- lib/eac_ruby_utils/ruby/on_clean_environment.rb
|
213
216
|
- lib/eac_ruby_utils/settings_provider.rb
|
214
217
|
- lib/eac_ruby_utils/simple_cache.rb
|
218
|
+
- lib/eac_ruby_utils/struct.rb
|
215
219
|
- lib/eac_ruby_utils/templates.rb
|
216
220
|
- lib/eac_ruby_utils/templates/directory.rb
|
217
221
|
- lib/eac_ruby_utils/templates/file.rb
|