eac_ruby_utils 0.56.2 → 0.58.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b3d020bb7af10057a1e59b06dab3c2373b2b08f41d5bfd5b04ef8447c5aae61
4
- data.tar.gz: 8125f0827f51e15f174df22b8a55e56646a322e013749fca184025ada77233e5
3
+ metadata.gz: '059525385419a316a364ba62f82e064c2eff52467f92e2a16adc0f60a0f04008'
4
+ data.tar.gz: 689cedcecce832ce4473697dd439c12c08c0fca1b5cef5464d5d8ed3c5b99e5f
5
5
  SHA512:
6
- metadata.gz: c084da333de3de3542c1a0d7ed961d22ecc10d21d98b5d3941f0bbbf6a867232a5384da17b8387b2095698932ce141d4614787d2f5181b4653f3b11f387e45a3
7
- data.tar.gz: 63eb2bdfb9f522195acb9ac712d1fefb6dfdc1c84f0da6c2b4dcf3eaef10a4aa41f4d6ff426ba019552d021b2ee762cef940c1d839cd1a61a55328aa54f6e7ed
6
+ metadata.gz: 26f4c05be42c42e86eade057a841dd0d6277479601b050a770bca40c36ff9300dd2f9d74c0ddf5f7f050ed37047cbfa3e6313f61cfe3a86c70a414bd367ed570
7
+ data.tar.gz: 9a981083c0ef681f5e20c77e965d05cbdd252035b2c1d6400c982da0258ab7b3f99f5225e58876d6ccaf40c8750a0ce60e957d50d1e107f28f0d2b2435635af9
@@ -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,42 @@
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 auto_set
18
+ ::Time.zone = auto
19
+ end
20
+
21
+ def by_debian_config
22
+ path = ::Pathname.new(DEBIAN_CONFIG_PATH)
23
+ path.exist? ? path.read.strip.presence : nil
24
+ end
25
+
26
+ def by_offset
27
+ ::ActiveSupport::TimeZone[::Time.now.getlocal.gmt_offset].name
28
+ end
29
+
30
+ def by_timedatectl
31
+ executable = ::EacRubyUtils::Envs.local.executable('timedatectl', '--version')
32
+ return nil unless executable.exist?
33
+
34
+ TIMEDATECTL_TIMEZONE_LINE_PATTERN.if_match(executable.command.execute!) { |m| m[1] }
35
+ end
36
+
37
+ def by_tz_env
38
+ ENV['TZ'].presence
39
+ end
40
+ end
41
+ end
42
+ 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,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.56.2'
4
+ VERSION = '0.58.1'
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.2
4
+ version: 0.58.1
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-28 00:00:00.000000000 Z
11
+ date: 2021-02-09 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
@@ -223,8 +227,6 @@ files:
223
227
  - lib/eac_ruby_utils/patches/string.rb
224
228
  - lib/eac_ruby_utils/patches/string/inflector.rb
225
229
  - lib/eac_ruby_utils/patches/time.rb
226
- - lib/eac_ruby_utils/patches/time/default_time_zone_set.rb
227
- - lib/eac_ruby_utils/patches/time/local_time_zone.rb
228
230
  - lib/eac_ruby_utils/paths_hash.rb
229
231
  - lib/eac_ruby_utils/paths_hash/entry_key_error.rb
230
232
  - lib/eac_ruby_utils/paths_hash/node.rb
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/patches/time/local_time_zone'
4
-
5
- ::Time.zone = ::Time.local_time_zone
@@ -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