eac_ruby_utils 0.121.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: f01b05501b3b07a9a61379167199fb3489be9b082a77ac5e1730ca271cbdc951
4
- data.tar.gz: ebc0eb54e6ee6d90d7fc3fffcf050b72ed10b1860d0db6c43213c7a241d2b27e
3
+ metadata.gz: 5fea41f96c275a53fedaeae53d07b81e356757859be5c17207d2eaa6924c5bda
4
+ data.tar.gz: 79e2fe2a6432169b0222d2dd785a49f3bc459a0004cca89e1534f6e58716401c
5
5
  SHA512:
6
- metadata.gz: 814b5652fb79d527e9331111697f438082a6012db38d74cf432ee8c7f855ea7cfb61a0e073807dec5acc6143b8453885fdeba2c82e0f55d94ea0b19426f3723e
7
- data.tar.gz: dcb8f3c8b0ee24d278bfe723bbefb8646b1ff7bcc6d21544ba853aba8750386130d0f242a40e727c392d16fe972759b7f8da1e1d91ffd39787a24ed57ab8d06b
6
+ metadata.gz: cf52648fabdb145fb750f0448aa758b122ae264a3947a50427ed3e08c28babc423b3cb2a091c0e3237d6edd6376203fa7abd071647c4269fbe286027116f323f
7
+ data.tar.gz: ee8f6519bc3074a512ed273c868e087da3ae79a50055d88118be6a109b6082737c911c12be4db91d10da333b1bb6cd2b7b33bb2cc01799d8bb9a634df6e10b18
@@ -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
@@ -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.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.121.0'
4
+ VERSION = '0.122.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.121.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: 2024-02-10 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