eac_ruby_utils 0.109.1 → 0.110.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: bff20dbb2a1dd1b005a28e508d41d93e1d430a4bdd7c936389556a97df7d300a
4
- data.tar.gz: 4ecfde5c8b6d86634197324bf05fd02879ae55ee58c8dad5db8eaeca4f1bf0cd
3
+ metadata.gz: c2b5cd79e1ec23311c26c6e444bc22ad3467fe4339414b040a6185c214f1941c
4
+ data.tar.gz: da8074cc3cdf8de32546c95088aa64bfc2b5d7bf8d56aff537de7f8d706ed077
5
5
  SHA512:
6
- metadata.gz: ce4e394feeb80d9907b52e497309aa1916f7b9f65413c72d00c18936bb77c7746a46ee0d1d4386fd3f3b7e2f5f1b77229e45b6ccd342b2b29a84a2c6aa4570ef
7
- data.tar.gz: bd726557052663349699fab114fbf3ae209b081d024a3dfc6a54a8a3b0f18f6fe69b72bb5f13aaed27a7309adca5786b2e00f48b86774cdf66f4af89cb58f373
6
+ metadata.gz: 56cdf581724ea7e15f46990e19fd70fc6b14dcc3d4d03bf995c8c15b20f615393561bf82e3008fb02a612cd1fc859dca3e6df1a397fb0383bcc721e4a805cae2
7
+ data.tar.gz: cc7a20c43187222d5c9ab0492bf45765a0d0fd6ec95a754012a61b62add8b34971a658a986034d188e15895fd4b06110dde7a597da5f6678ad072e608b199630
@@ -1,25 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/common_constructor'
3
4
  require 'eac_ruby_utils/inflector'
4
5
 
5
6
  module EacRubyUtils
6
7
  module Listable
7
- class Value
8
- attr_reader :value, :key
9
-
10
- def initialize(list, value, key, translation_required = true)
11
- @list = list
12
- @value = value
13
- @key = key
14
- @translation_required = translation_required
15
- end
8
+ class Item
9
+ common_constructor :list, :value, :key, :translation_required, default: [true]
16
10
 
17
11
  def to_s
18
- "I: #{@list.item}, V: #{@value}, K: #{@key}"
12
+ "I: #{list.item}, V: #{value}, K: #{key}"
19
13
  end
20
14
 
21
15
  def constant_name
22
- ::EacRubyUtils::Inflector.variableize("#{@list.item}_#{@key}").upcase
16
+ ::EacRubyUtils::Inflector.variableize("#{list.item}_#{key}").upcase
23
17
  end
24
18
 
25
19
  def label
@@ -36,13 +30,13 @@ module EacRubyUtils
36
30
  end
37
31
 
38
32
  def translation_required?
39
- @translation_required
33
+ translation_required
40
34
  end
41
35
 
42
36
  private
43
37
 
44
38
  def translate(translate_key)
45
- full_translate_key = "#{@list.i18n_key}.#{@key}.#{translate_key}"
39
+ full_translate_key = "#{list.i18n_key}.#{key}.#{translate_key}"
46
40
  if !::I18n.exists?(full_translate_key) && !translation_required?
47
41
  ''
48
42
  else
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/listable/value'
3
+ require 'eac_ruby_utils/listable/item'
4
4
 
5
5
  module EacRubyUtils
6
6
  module Listable
@@ -18,13 +18,23 @@ module EacRubyUtils
18
18
  end
19
19
 
20
20
  def blank_value
21
- @blank_value ||= ::EacRubyUtils::Listable::Value.new(self, BLANK_VALUE, BLANK_KEY, false)
21
+ @blank_value ||= ::EacRubyUtils::Listable::Item.new(self, BLANK_VALUE, BLANK_KEY, false)
22
22
  end
23
23
 
24
24
  def each_value(&block)
25
25
  values.each(&block)
26
26
  end
27
27
 
28
+ # @return [EacRubyUtils::Listable::Item, nil]
29
+ def item_by_value(value)
30
+ @values.values.find { |item| item.value == value }
31
+ end
32
+
33
+ # @return [EacRubyUtils::Listable::Item]
34
+ def item_by_value!(value)
35
+ item_by_value(value) || raise(::KeyError, "Value not found: #{value}")
36
+ end
37
+
28
38
  def values
29
39
  @values.values.map(&:value)
30
40
  end
@@ -59,7 +69,7 @@ module EacRubyUtils
59
69
  "eac_ruby_utils.listable.#{class_i18n_key}.#{item}"
60
70
  end
61
71
 
62
- # @return [EacRubyUtils::Listable::Value, nil]
72
+ # @return [EacRubyUtils::Listable::Item, nil]
63
73
  def instance_value(instance)
64
74
  v = instance.send(item)
65
75
  return blank_value if v.blank?
@@ -109,7 +119,7 @@ module EacRubyUtils
109
119
  def build_values(labels)
110
120
  vs = {}
111
121
  parse_labels(labels).each do |value, key|
112
- v = Value.new(self, value, key)
122
+ v = ::EacRubyUtils::Listable::Item.new(self, value, key)
113
123
  vs[v.value] = v
114
124
  end
115
125
  vs
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ class Pathname
6
+ # Invoke +mkpath+ for parent path and return +self+.
7
+ # @return [self]
8
+ def assert_parent
9
+ parent.mkpath
10
+ self
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.109.1'
4
+ VERSION = '0.110.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.109.1
4
+ version: 0.110.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-12-16 00:00:00.000000000 Z
11
+ date: 2022-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -197,11 +197,11 @@ files:
197
197
  - lib/eac_ruby_utils/listable/class_methods.rb
198
198
  - lib/eac_ruby_utils/listable/instance_methods.rb
199
199
  - lib/eac_ruby_utils/listable/integer_list.rb
200
+ - lib/eac_ruby_utils/listable/item.rb
200
201
  - lib/eac_ruby_utils/listable/list.rb
201
202
  - lib/eac_ruby_utils/listable/lists.rb
202
203
  - lib/eac_ruby_utils/listable/string_list.rb
203
204
  - lib/eac_ruby_utils/listable/symbol_list.rb
204
- - lib/eac_ruby_utils/listable/value.rb
205
205
  - lib/eac_ruby_utils/local_time_zone.rb
206
206
  - lib/eac_ruby_utils/locales.rb
207
207
  - lib/eac_ruby_utils/locales/from_all_gems.rb
@@ -258,6 +258,7 @@ files:
258
258
  - lib/eac_ruby_utils/patches/object/to_pathname.rb
259
259
  - lib/eac_ruby_utils/patches/object/to_uri.rb
260
260
  - lib/eac_ruby_utils/patches/pathname.rb
261
+ - lib/eac_ruby_utils/patches/pathname/assert_parent.rb
261
262
  - lib/eac_ruby_utils/patches/pathname/basename_noext.rb
262
263
  - lib/eac_ruby_utils/patches/pathname/basename_sub.rb
263
264
  - lib/eac_ruby_utils/patches/pathname/if_exist.rb