eac_ruby_utils 0.92.0 → 0.94.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: 0d74824328749892433f50acfff8dd16d867abab61ab7115c55f4e3de45a8a8c
4
- data.tar.gz: 04b5e0aa890040410a27a38597dc8d46758f406666ae90042bd0ff13fa0cdb60
3
+ metadata.gz: bd005dee6ec45f3359d56a0e707921cd9d3e702f105ae3b7ad3e8c7e95586874
4
+ data.tar.gz: 6b1efc6a5f813f271722d0057127bd869e3fb273351e8414939fa9e187151b06
5
5
  SHA512:
6
- metadata.gz: 908be31eb44d2d44909f78f7ef5e3a7bb5bf7f5a731d6e0640604c83cf655ca8f49d854114abc9f1a72b3c918999bd651a6bcc78b2a885083d057331a0d4c4eb
7
- data.tar.gz: 2bab742f8f453836e06bca57d3528fa442542c53aad1c22fdde7563dfb2d29ffa41ce35700c474b12e338be97cfe2990270882292eb102392868721c25023679
6
+ metadata.gz: 07c916d88b0459d32fc3f5c3f6b196b1b3214d3462a195686116a6c6e4ca9144c99a1958bc8dc29485a963cf8704cbaa602fa710a153b21ecb0b2bab37918062
7
+ data.tar.gz: ea2ff669feb2ed217c4b99c67fbd54e79fd118c72a9befc161030b4f1b618fc0c8a4c99188621c3fe53788afa700a2c697209967a8805ab6e11d6c12fdbb880e
@@ -5,15 +5,23 @@ require 'open3'
5
5
  module EacRubyUtils
6
6
  module Envs
7
7
  class Process
8
+ EXIT_CODE_KEY = :exit_code
9
+ ERR_KEY = :stderr
10
+ OUT_KEY = :stdout
11
+
8
12
  def initialize(command)
9
- @data = { command: command }
10
- @data[:stdout], @data[:stderr], @data[:exit_code] = Open3.capture3(command)
11
- @data[:exit_code] = @data[:exit_code].to_i
13
+ self.data = { command: command }
14
+ data[OUT_KEY], data[ERR_KEY], data[EXIT_CODE_KEY] = Open3.capture3(command)
15
+ data[EXIT_CODE_KEY] = data[EXIT_CODE_KEY].to_i
12
16
  end
13
17
 
14
18
  def to_h
15
- @data.dup
19
+ data.dup
16
20
  end
21
+
22
+ private
23
+
24
+ attr_accessor :data
17
25
  end
18
26
  end
19
27
  end
@@ -1,8 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/listable/value'
4
+
3
5
  module EacRubyUtils
4
6
  module Listable
5
7
  class List
8
+ BLANK_VALUE = nil
9
+ BLANK_KEY = :__blank
10
+
6
11
  attr_reader :item
7
12
 
8
13
  def initialize(lists, item, labels)
@@ -12,6 +17,10 @@ module EacRubyUtils
12
17
  apply_constants
13
18
  end
14
19
 
20
+ def blank_value
21
+ @blank_value ||= ::EacRubyUtils::Listable::Value.new(self, BLANK_VALUE, BLANK_KEY, false)
22
+ end
23
+
15
24
  def each_value(&block)
16
25
  values.each(&block)
17
26
  end
@@ -42,11 +51,14 @@ module EacRubyUtils
42
51
  "eac_ruby_utils.listable.#{class_i18n_key}.#{item}"
43
52
  end
44
53
 
54
+ # @return [EacRubyUtils::Listable::Value, nil]
45
55
  def instance_value(instance)
46
56
  v = instance.send(item)
57
+ return blank_value if v.blank?
47
58
  return @values[v] if @values.key?(v)
48
59
 
49
- raise "List value unkown: #{v} (Source: #{@lists.source}, Item: #{item})"
60
+ raise "List value unkown: \"#{v}\" (Source: #{@lists.source}, Item: #{item}, Instance: " \
61
+ "#{instance.to_debug}, Values: #{@values.keys})"
50
62
  end
51
63
 
52
64
  def value_valid?(value)
@@ -7,10 +7,11 @@ module EacRubyUtils
7
7
  class Value
8
8
  attr_reader :value, :key
9
9
 
10
- def initialize(list, value, key)
10
+ def initialize(list, value, key, translation_required = true)
11
11
  @list = list
12
12
  @value = value
13
13
  @key = key
14
+ @translation_required = translation_required
14
15
  end
15
16
 
16
17
  def to_s
@@ -29,10 +30,19 @@ module EacRubyUtils
29
30
  translate('description')
30
31
  end
31
32
 
33
+ def translation_required?
34
+ @translation_required
35
+ end
36
+
32
37
  private
33
38
 
34
39
  def translate(translate_key)
35
- ::I18n.t("#{@list.i18n_key}.#{@key}.#{translate_key}")
40
+ full_translate_key = "#{@list.i18n_key}.#{@key}.#{translate_key}"
41
+ if !::I18n.exists?(full_translate_key) && !translation_required?
42
+ ''
43
+ else
44
+ ::I18n.t(full_translate_key)
45
+ end
36
46
  end
37
47
  end
38
48
  end
@@ -1,6 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Object
4
+ def pretty_debug
5
+ STDERR.write(pretty_inspect)
6
+
7
+ self
8
+ end
9
+
4
10
  def print_debug
5
11
  STDERR.write(to_debug + "\n")
6
12
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.92.0'
4
+ VERSION = '0.94.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.92.0
4
+ version: 0.94.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: 2022-03-22 00:00:00.000000000 Z
11
+ date: 2022-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport