eac_ruby_utils 0.120.0 → 0.122.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: c58a76e4652914930ee4d510d2dd7cf1a577122b2c634eadf03f95e620d17a80
4
- data.tar.gz: deb45ec59e21c72844fa5fbf4f8c787c2c2534d1baa0829ceba3babed5fe38e5
3
+ metadata.gz: 5fea41f96c275a53fedaeae53d07b81e356757859be5c17207d2eaa6924c5bda
4
+ data.tar.gz: 79e2fe2a6432169b0222d2dd785a49f3bc459a0004cca89e1534f6e58716401c
5
5
  SHA512:
6
- metadata.gz: 9655fb0dcaac2b8adfe6701e8aa04cc95153a8d43d86ce3c08c31359a939eaa937b024dd5619671879e5db491bee465be804aee3c9f5f791c16676b283f53def
7
- data.tar.gz: 6c3c8e2736e9e9bea326026bf9be568a040441c5e060c402db24844b889d512d11dd1802270a278fa450c98320ff68e028f27d689601d6c861c0d1b35f4d967c
6
+ metadata.gz: cf52648fabdb145fb750f0448aa758b122ae264a3947a50427ed3e08c28babc423b3cb2a091c0e3237d6edd6376203fa7abd071647c4269fbe286027116f323f
7
+ data.tar.gz: ee8f6519bc3074a512ed273c868e087da3ae79a50055d88118be6a109b6082737c911c12be4db91d10da333b1bb6cd2b7b33bb2cc01799d8bb9a634df6e10b18
@@ -73,7 +73,7 @@ module EacRubyUtils
73
73
  def initialize(args_consumer, arg, message)
74
74
  @args_consumer = args_consumer
75
75
  @arg = arg
76
- super "#{message} (Arg: #{arg}, Args Consumer: #{args_consumer})"
76
+ super("#{message} (Arg: #{arg}, Args Consumer: #{args_consumer})")
77
77
  end
78
78
  end
79
79
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  module EacRubyUtils
4
4
  class Compact
5
+ ATTRIBUTE_SEPARATOR = '.'
6
+
5
7
  attr_reader :object, :attributes
6
8
 
7
9
  def initialize(object, attributes)
@@ -9,14 +11,22 @@ module EacRubyUtils
9
11
  @attributes = attributes
10
12
  end
11
13
 
14
+ # @param attr_path [String, Symbol] A path separated by +ATTRIBUTE_SEPARATOR+.
15
+ # @return [Object]
16
+ def attribute_value(attr_path)
17
+ attr_path.to_s.split(ATTRIBUTE_SEPARATOR).inject(object) do |a, e|
18
+ a.send(e)
19
+ end
20
+ end
21
+
12
22
  # @return [Array]
13
23
  def to_a
14
- attributes.map { |attr| object.send(attr) }
24
+ attributes.map { |attr| attribute_value(attr) }
15
25
  end
16
26
 
17
27
  # @return [Hash]
18
28
  def to_h
19
- attributes.to_h { |attr| [attr.to_sym, object.send(attr)] }
29
+ attributes.to_h { |attr| [attr.to_sym, attribute_value(attr)] }
20
30
  end
21
31
  end
22
32
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/object/blank'
4
+
5
+ class Hash
6
+ # @return +block.call(fetch(key))+ if +self+ has the key +key+, +default_value+ otherwise.
7
+ def if_key(key, default_value = nil)
8
+ return default_value unless key?(key)
9
+
10
+ block_given? ? yield(fetch(key)) : fetch(key)
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kernel
4
+ # Raise exception with text "Invalid branch reached".
5
+ def ibr(message = nil)
6
+ s = "Invalid branch reached (Called in #{caller.first})"
7
+ s += ": #{message}" if message
8
+ raise s
9
+ end
10
+ end
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/compact'
3
4
  require 'eac_ruby_utils/patches/object/if_present'
4
5
  require 'pp'
5
6
 
6
7
  class Object
7
- def compact_debug(*methods_names)
8
- methods_names.each do |method_name|
9
- send(method_name).print_debug(label: method_name)
8
+ # @param attributes [Enumerable<Symbol>] Attributes for +EacRubyUtils::Compact.new+.
9
+ # @return [void]
10
+ def compact_debug(*attributes)
11
+ ::EacRubyUtils::Compact.new(self, attributes).to_h.each do |name, value|
12
+ value.print_debug(label: name)
10
13
  end
11
14
  end
12
15
 
@@ -35,6 +38,7 @@ class Object
35
38
  end
36
39
 
37
40
  def print_debug_title(title)
41
+ title = title.to_s
38
42
  char = '='
39
43
  $stderr.write("#{char * (4 + title.length)}\n")
40
44
  $stderr.write("#{char} #{title} #{char}\n")
@@ -1,17 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/compact'
4
+
3
5
  module EacRubyUtils
4
6
  module Speaker
5
7
  module Sender
6
- delegate :error, :fatal_error, :info, :infom, :title, :success, :warn, to: :speaker_receiver
7
-
8
- def infov(*args)
9
- speaker_receiver.infov(*args)
10
- end
11
-
12
- delegate :out, to: :speaker_receiver
13
-
14
- delegate :puts, to: :speaker_receiver
8
+ delegate :error, :fatal_error, :info, :infom, :infov, :out, :puts, :title, :success, :warn,
9
+ to: :speaker_receiver
15
10
 
16
11
  # Shortcut to [EacRubyUtils::Speaker.current_receiver].
17
12
  #
@@ -20,6 +15,16 @@ module EacRubyUtils
20
15
  ::EacRubyUtils::Speaker.current_receiver
21
16
  end
22
17
 
18
+ # @param attributes [Enumerable<Symbol>] Attributes for +EacRubyUtils::Compact.new+.
19
+ # @return [self]
20
+ def compact_infov(*attributes)
21
+ ::EacRubyUtils::Compact.new(self, attributes).to_h.each do |k, v|
22
+ infov k, v
23
+ end
24
+
25
+ self
26
+ end
27
+
23
28
  # Options:
24
29
  # +bool+ ([Boolean], default: +false+): requires a answer "yes" or "no".
25
30
  # +list+ ([Hash] or [Array], default: +nil+): requires a answer from a list.
@@ -57,7 +57,7 @@ module EacRubyUtils
57
57
  end
58
58
 
59
59
  def property_methods
60
- data.keys.flat_map { |k| [k.to_sym, "#{k}?".to_sym] }
60
+ data.keys.flat_map { |k| [k.to_sym, :"#{k}?"] }
61
61
  end
62
62
  end
63
63
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.120.0'
4
+ VERSION = '0.122.0'
5
5
  end
@@ -19,7 +19,7 @@ module EacRubyUtils
19
19
  end
20
20
 
21
21
  def load(string)
22
- ::YAML.safe_load(string, permitted_classes)
22
+ ::YAML.safe_load(string, permitted_classes: permitted_classes)
23
23
  end
24
24
 
25
25
  def load_file(path)
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.120.0
4
+ version: 0.122.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: 2023-11-21 00:00:00.000000000 Z
11
+ date: 2024-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: '2.8'
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 2.8.5
42
+ version: 2.8.6
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,7 +49,7 @@ dependencies:
49
49
  version: '2.8'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 2.8.5
52
+ version: 2.8.6
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: bundler
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -235,10 +235,12 @@ files:
235
235
  - lib/eac_ruby_utils/patches/enumerator/current.rb
236
236
  - lib/eac_ruby_utils/patches/enumerator/stopped.rb
237
237
  - lib/eac_ruby_utils/patches/hash.rb
238
+ - lib/eac_ruby_utils/patches/hash/if_key.rb
238
239
  - lib/eac_ruby_utils/patches/hash/options_consumer.rb
239
240
  - lib/eac_ruby_utils/patches/hash/sym_keys_hash.rb
240
241
  - lib/eac_ruby_utils/patches/hash/to_struct.rb
241
242
  - lib/eac_ruby_utils/patches/kernel.rb
243
+ - lib/eac_ruby_utils/patches/kernel/ibr.rb
242
244
  - lib/eac_ruby_utils/patches/kernel/nyi.rb
243
245
  - lib/eac_ruby_utils/patches/module.rb
244
246
  - lib/eac_ruby_utils/patches/module/abstract_methods.rb