eac_ruby_utils 0.56.1 → 0.58.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c07518f84851a310f039de5bb30de575649d8d4b2b089284165bf72a71f4dab
4
- data.tar.gz: 18b2be4e3d6243e34086b266f32f84713544d3ca3bfb76aaef7e08560a89dfd0
3
+ metadata.gz: 123493b4c18d48f7366d734db4d722e0e72dd1ac0463649a45a3552c5bc8b6b7
4
+ data.tar.gz: 5858bc58b340efed7d26cf17695535a3fb26abbb121f53c4889d6f87c9f03a25
5
5
  SHA512:
6
- metadata.gz: d8a71000fdee630a9811dc77cc2ccbd8eca51d6365af93f7c3f44b17d5983daa1b5afa4a5701f0a35a1aaa9b1e7009a880a827d4523f3ad9ea7bb8f1484e04b3
7
- data.tar.gz: a50db86faa6769219a1abafb43d23e392a6f0e13f77f93851c4fbfb22e250df25f143a408a6a3f169eb978a71339ee467075a7b1d0acf921c3b6720ee011ef66
6
+ metadata.gz: 7b3c80642b58e8eb315ca82d8d760467a7404585771907a9dbe3344e3aa3b00991e7d319beee042ee45eb36939cf93af35e38f76bd0d1642a7e9b383bdf3f023
7
+ data.tar.gz: d4dc7641afd5d36e818fcfe0e50f59c6f0cb2dd596fef6a7cf4fc31e0b19929638232669bf3f60e4c9da6a42616610517633f69bd7363d05120cf5b8a5192b0c
@@ -38,7 +38,7 @@ module EacRubyUtils
38
38
  def run_with_subcommand
39
39
  if subcommand_name
40
40
  check_valid_subcommand
41
- subcommand.run
41
+ subcommand_run
42
42
  else
43
43
  run_without_subcommand
44
44
  end
@@ -52,6 +52,15 @@ module EacRubyUtils
52
52
  )
53
53
  end
54
54
 
55
+ def subcommand_run
56
+ if !subcommand.is_a?(::EacRubyUtils::Console::DocoptRunner) &&
57
+ subcommand.respond_to?(:run_run)
58
+ subcommand.run_run
59
+ else
60
+ subcommand.run
61
+ end
62
+ end
63
+
55
64
  def target_doc
56
65
  super.gsub(SUBCOMMANDS_MACRO,
57
66
  "#{target_doc_subcommand_arg} [#{SUBCOMMAND_ARGS_ARG}...]") +
@@ -57,8 +57,6 @@ module EacRubyUtils
57
57
  user_check_file(path)
58
58
  elsif path.directory?
59
59
  inner_check_directory(path, level)
60
- else
61
- raise "Unknown filesystem object: #{path}"
62
60
  end
63
61
  end
64
62
 
@@ -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, '_').gsub(/_+/, '_').gsub(/_\z/, '').gsub(/\A_/, '').downcase
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
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub(__FILE__)
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kernel
4
+ # Raise exception with text "Not yet implemented".
5
+ def nyi
6
+ raise "Not yet implemented (Called in #{caller.first})"
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/string/inflections'
4
+ require 'eac_ruby_utils/templates/searcher'
5
+
6
+ class Module
7
+ def template
8
+ @template ||= ::EacRubyUtils::Templates::Searcher.default.template(name.underscore)
9
+ end
10
+ end
@@ -1,15 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/core_ext/string/inflections'
4
- require 'eac_ruby_utils/templates/searcher'
3
+ require 'eac_ruby_utils/patches/module/template'
5
4
 
6
5
  class Object
7
- class << self
8
- def template
9
- @template ||= ::EacRubyUtils::Templates::Searcher.default.template(name.underscore)
10
- end
11
- end
12
-
13
6
  def template
14
7
  self.class.template
15
8
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/patches/time/local_time_zone'
3
+ require 'active_support/core_ext/time/zones'
4
+ require 'eac_ruby_utils/local_time_zone'
4
5
 
5
- ::Time.zone = ::Time.local_time_zone
6
+ ::Time.zone = ::EacRubyUtils::LocalTimeZone.auto
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.56.1'
4
+ VERSION = '0.58.0'
5
5
  end
@@ -14,10 +14,18 @@ module EacRubyUtils
14
14
  ::YAML.dump(sanitize(object))
15
15
  end
16
16
 
17
+ def dump_file(path, object)
18
+ ::File.write(path.to_s, dump(object))
19
+ end
20
+
17
21
  def load(string)
18
22
  ::YAML.safe_load(string, permitted_classes)
19
23
  end
20
24
 
25
+ def load_file(path)
26
+ load(::File.read(path.to_s))
27
+ end
28
+
21
29
  def permitted_classes
22
30
  DEFAULT_PERMITTED_CLASSES
23
31
  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.56.1
4
+ version: 0.58.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-12-27 00:00:00.000000000 Z
11
+ date: 2021-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -186,6 +186,7 @@ files:
186
186
  - lib/eac_ruby_utils/listable/string_list.rb
187
187
  - lib/eac_ruby_utils/listable/symbol_list.rb
188
188
  - lib/eac_ruby_utils/listable/value.rb
189
+ - lib/eac_ruby_utils/local_time_zone.rb
189
190
  - lib/eac_ruby_utils/on_clean_ruby_environment.rb
190
191
  - lib/eac_ruby_utils/options_consumer.rb
191
192
  - lib/eac_ruby_utils/patch.rb
@@ -200,6 +201,8 @@ files:
200
201
  - lib/eac_ruby_utils/patches/hash.rb
201
202
  - lib/eac_ruby_utils/patches/hash/options_consumer.rb
202
203
  - lib/eac_ruby_utils/patches/hash/sym_keys_hash.rb
204
+ - lib/eac_ruby_utils/patches/kernel.rb
205
+ - lib/eac_ruby_utils/patches/kernel/nyi.rb
203
206
  - lib/eac_ruby_utils/patches/module.rb
204
207
  - lib/eac_ruby_utils/patches/module/abstract_methods.rb
205
208
  - lib/eac_ruby_utils/patches/module/common_concern.rb
@@ -209,6 +212,7 @@ files:
209
212
  - lib/eac_ruby_utils/patches/module/patch.rb
210
213
  - lib/eac_ruby_utils/patches/module/require_sub.rb
211
214
  - lib/eac_ruby_utils/patches/module/simple_cache.rb
215
+ - lib/eac_ruby_utils/patches/module/template.rb
212
216
  - lib/eac_ruby_utils/patches/object.rb
213
217
  - lib/eac_ruby_utils/patches/object/asserts.rb
214
218
  - lib/eac_ruby_utils/patches/object/debug.rb
@@ -224,7 +228,6 @@ files:
224
228
  - lib/eac_ruby_utils/patches/string/inflector.rb
225
229
  - lib/eac_ruby_utils/patches/time.rb
226
230
  - lib/eac_ruby_utils/patches/time/default_time_zone_set.rb
227
- - lib/eac_ruby_utils/patches/time/local_time_zone.rb
228
231
  - lib/eac_ruby_utils/paths_hash.rb
229
232
  - lib/eac_ruby_utils/paths_hash/entry_key_error.rb
230
233
  - lib/eac_ruby_utils/paths_hash/node.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