eac_ruby_utils 0.58.1 → 0.59.0

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: '059525385419a316a364ba62f82e064c2eff52467f92e2a16adc0f60a0f04008'
4
- data.tar.gz: 689cedcecce832ce4473697dd439c12c08c0fca1b5cef5464d5d8ed3c5b99e5f
3
+ metadata.gz: 548ad31ed6381e0a51802ea856dfa885fdaef16080305285698872baa9dc9b24
4
+ data.tar.gz: ee4ddee8e898704ef248d82296d7cb63093a3ff8a72e929b6815c854e8e66e70
5
5
  SHA512:
6
- metadata.gz: 26f4c05be42c42e86eade057a841dd0d6277479601b050a770bca40c36ff9300dd2f9d74c0ddf5f7f050ed37047cbfa3e6313f61cfe3a86c70a414bd367ed570
7
- data.tar.gz: 9a981083c0ef681f5e20c77e965d05cbdd252035b2c1d6400c982da0258ab7b3f99f5225e58876d6ccaf40c8750a0ce60e957d50d1e107f28f0d2b2435635af9
6
+ metadata.gz: 2dcbd2e28932d4a287e94798511973b1ec0803838294f2eba2d5fb7ea5e7399ee5092d2bde598e5f403195c3832bdc57a4de2a9ba7514ac4f3c9ff5f23523243
7
+ data.tar.gz: 8a3259581c69448604dcc452f7ede39ef6ba1eaf9081d609c837e16377aa11bdd0bba9100256226334b7863149a5d93ad43d4410b4d7b660ce61f6498850612c
@@ -10,6 +10,7 @@ module EacRubyUtils
10
10
  class << self
11
11
  TIMEDATECTL_TIMEZONE_LINE_PATTERN = %r{\s*Time zone:\s*(\S+/\S+)\s}.freeze
12
12
 
13
+ # @return [ActiveSupport::TimeZone]
13
14
  def auto
14
15
  %w[tz_env debian_config offset].lazy.map { |s| send("by_#{s}") }.find(&:present?)
15
16
  end
@@ -18,22 +19,27 @@ module EacRubyUtils
18
19
  ::Time.zone = auto
19
20
  end
20
21
 
22
+ # @return [ActiveSupport::TimeZone]
21
23
  def by_debian_config
22
24
  path = ::Pathname.new(DEBIAN_CONFIG_PATH)
23
- path.exist? ? path.read.strip.presence : nil
25
+ path.exist? ? path.read.strip.if_present { |v| ::ActiveSupport::TimeZone[v] } : nil
24
26
  end
25
27
 
28
+ # @return [ActiveSupport::TimeZone]
26
29
  def by_offset
27
- ::ActiveSupport::TimeZone[::Time.now.getlocal.gmt_offset].name
30
+ ::ActiveSupport::TimeZone[::Time.now.getlocal.gmt_offset]
28
31
  end
29
32
 
33
+ # @return [ActiveSupport::TimeZone]
30
34
  def by_timedatectl
31
35
  executable = ::EacRubyUtils::Envs.local.executable('timedatectl', '--version')
32
36
  return nil unless executable.exist?
33
37
 
34
38
  TIMEDATECTL_TIMEZONE_LINE_PATTERN.if_match(executable.command.execute!) { |m| m[1] }
39
+ .if_present { |v| ::ActiveSupport::TimeZone[v] }
35
40
  end
36
41
 
42
+ # @return [ActiveSupport::TimeZone]
37
43
  def by_tz_env
38
44
  ENV['TZ'].presence
39
45
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patch'
4
+ require 'eac_ruby_utils/settings_provider'
5
+
6
+ class Class
7
+ def enable_settings_provider
8
+ ::EacRubyUtils.patch(self, ::EacRubyUtils::SettingsProvider)
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Object
4
+ # @return +block.call(self)+ if +self+ is not nil, +default_value+ otherwise.
5
+ def if_not_nil(default_value = nil)
6
+ return default_value if nil?
7
+
8
+ block_given? ? yield(self) : self
9
+ end
10
+
11
+ # @return +yield+ if +self+ is nil, +self+ otherwise.
12
+ def if_nil
13
+ return yield if nil? && block_given?
14
+
15
+ self
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/local_time_zone'
4
+
5
+ class Time
6
+ class << self
7
+ def required_zone
8
+ zone || ::EacRubyUtils::LocalTimeZone.auto || raise('No zone set or discovered')
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.58.1'
4
+ VERSION = '0.59.0'
5
5
  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.58.1
4
+ version: 0.59.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: 2021-02-09 00:00:00.000000000 Z
11
+ date: 2021-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -193,6 +193,7 @@ files:
193
193
  - lib/eac_ruby_utils/patches.rb
194
194
  - lib/eac_ruby_utils/patches/class.rb
195
195
  - lib/eac_ruby_utils/patches/class/common_constructor.rb
196
+ - lib/eac_ruby_utils/patches/class/settings_provider.rb
196
197
  - lib/eac_ruby_utils/patches/enumerable.rb
197
198
  - lib/eac_ruby_utils/patches/enumerable/boolean_combinations.rb
198
199
  - lib/eac_ruby_utils/patches/enumerator.rb
@@ -216,6 +217,7 @@ files:
216
217
  - lib/eac_ruby_utils/patches/object.rb
217
218
  - lib/eac_ruby_utils/patches/object/asserts.rb
218
219
  - lib/eac_ruby_utils/patches/object/debug.rb
220
+ - lib/eac_ruby_utils/patches/object/if_nil.rb
219
221
  - lib/eac_ruby_utils/patches/object/if_present.rb
220
222
  - lib/eac_ruby_utils/patches/object/if_respond.rb
221
223
  - lib/eac_ruby_utils/patches/object/template.rb
@@ -227,6 +229,7 @@ files:
227
229
  - lib/eac_ruby_utils/patches/string.rb
228
230
  - lib/eac_ruby_utils/patches/string/inflector.rb
229
231
  - lib/eac_ruby_utils/patches/time.rb
232
+ - lib/eac_ruby_utils/patches/time/required_zone.rb
230
233
  - lib/eac_ruby_utils/paths_hash.rb
231
234
  - lib/eac_ruby_utils/paths_hash/entry_key_error.rb
232
235
  - lib/eac_ruby_utils/paths_hash/node.rb