tater 3.0.4 → 3.0.5

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: 1913c7bc9ecb58cbb7ff7c4239978c8401116a954f967e1fd1e557ad30b0e7bd
4
- data.tar.gz: cd65a35921e999375affaf4a38717fc14c6938285f3ad1d4258727494a212d40
3
+ metadata.gz: '08a174e27ecb08955ba15997b8b71995aff8a77cbf82bb08514ba5dcd6e404dd'
4
+ data.tar.gz: c9f78478bc5f1b7a48b038add4f3c05230dc6083ccada5d1de00974b1dbd08f8
5
5
  SHA512:
6
- metadata.gz: 8744cffa6df1821728ee83f221899d7b5dae739c9420f0ce40bbd02f9b7a7d1388aeed8f54a3d029663a2843b0fca915cd277dc688b044a559c994630695bfc1
7
- data.tar.gz: 4e0cfde2f00feaf6e3ce76aec920b0f56a208dfc59e18f0af0c679fe1f8d733ce6c5343bdafc36df33bb2170b6ac660e36d906161273ddf7a3c9fc0a96cf78aa
6
+ metadata.gz: 27b9c2ad757cb5a51bf0ce3a792a92912bc3d8a2f9e82c761621396417480b6c82088222cd9e2c552d2309381d8feb0399466cade27b75fd2fb29d6eab2552b0
7
+ data.tar.gz: baf324c10b838927b0aedc2ac5babafed538acbdaeb7a4f7a5e6aebf8731d53037ec2dad4870d459a90056c9b9c2442d59ed6efaf5d94dbb74341f6a6ae3c14d
data/README.org CHANGED
@@ -1,6 +1,7 @@
1
1
  * Tater
2
2
 
3
3
  [[https://badge.fury.io/rb/tater][https://badge.fury.io/rb/tater.svg]]
4
+ [[https://github.com/evanleck/tater/actions/workflows/main.yml][https://github.com/evanleck/tater/actions/workflows/main.yml/badge.svg]]
4
5
 
5
6
  Tater is an internationalization (i18n) and localization (l10n) library designed
6
7
  for simplicity. It doesn't do everything that other libraries do, but that's by
@@ -238,7 +239,7 @@ Tater.new.translate('nope', default: 'Yep!') # => 'Yep!'
238
239
  ** Procs and messages in Ruby
239
240
 
240
241
  Ruby files can be used to store messages in addition to YAML, so long as the
241
- Ruby file returns a =Hash= when evalled.
242
+ Ruby file returns a =Hash= when evaluated.
242
243
 
243
244
  #+begin_src ruby
244
245
  {
@@ -281,7 +282,7 @@ Locales will be tried in order and whichever one matches first will be returned.
281
282
 
282
283
  ** Limitations
283
284
 
284
- - It is not pluggable, it does what it does and that's it.
285
+ - It is not plug-able, it does what it does and that's it.
285
286
  - It doesn't handle pluralization yet, though it may in the future.
286
287
 
287
288
  ** Why?
@@ -292,6 +293,6 @@ file that handles the basics of lookup and interpolation.
292
293
 
293
294
  ** Trivia
294
295
 
295
- I was orininally going to call this library "Translator" but with a [[https://en.wikipedia.org/wiki/Numeronym][numeronym]]
296
+ I was originally going to call this library "Translator" but with a [[https://en.wikipedia.org/wiki/Numeronym][numeronym]]
296
297
  like I18n: "t8r". I looked at it for a while but I read it as "tater" instead
297
298
  of "tee-eight-arr" so I figured I'd just name it Tater. Tater the translator.
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ class Tater
3
+ VERSION = '3.0.5'
4
+ end
data/lib/tater.rb CHANGED
@@ -4,8 +4,9 @@ require 'date'
4
4
  require 'time'
5
5
  require 'yaml'
6
6
 
7
- require 'tater/utils'
8
7
  require 'tater/hash' unless Hash.method_defined?(:except)
8
+ require 'tater/utils'
9
+ require 'tater/version'
9
10
 
10
11
  # Tater is a internationalization (i18n) and localization (l10n) library
11
12
  # designed for speed and simplicity.
@@ -22,6 +23,11 @@ class Tater
22
23
  # Needed for Ruby < 3.
23
24
  using HashExcept unless Hash.method_defined?(:except)
24
25
 
26
+ # An array of the available locale codes found in loaded messages.
27
+ #
28
+ # @return [Array<String>]
29
+ attr_reader :available
30
+
25
31
  # @return [String]
26
32
  attr_reader :locale
27
33
 
@@ -37,6 +43,8 @@ class Tater
37
43
  # @param path [String]
38
44
  # A path to search for YAML or Ruby files to load messages from.
39
45
  def initialize(cascade: false, locale: nil, messages: nil, path: nil)
46
+ @available = []
47
+ @cache = {}
40
48
  @cascade = cascade
41
49
  @locale = locale
42
50
  @messages = {}
@@ -45,6 +53,11 @@ class Tater
45
53
  load(messages: messages) if messages
46
54
  end
47
55
 
56
+ # @return [String]
57
+ def inspect
58
+ %(#<Tater:#{ object_id } @cascade=#{ @cascade } @locale="#{ @locale }" @available=#{ @available }>)
59
+ end
60
+
48
61
  # Do lookups cascade by default?
49
62
  #
50
63
  # @return [Boolean]
@@ -52,13 +65,6 @@ class Tater
52
65
  @cascade
53
66
  end
54
67
 
55
- # An array of the available locale codes found in loaded messages.
56
- #
57
- # @return [Array]
58
- def available
59
- @available ||= messages.keys
60
- end
61
-
62
68
  # Is this locale available in our current set of messages?
63
69
  #
64
70
  # @return [Boolean]
@@ -89,12 +95,12 @@ class Tater
89
95
  @messages = Utils.deep_merge(@messages, Utils.deep_stringify_keys(messages)) if messages
90
96
  @messages = Utils.deep_freeze(@messages)
91
97
 
92
- # Gotta recalculate available locales after updating.
93
- remove_instance_variable(:@available) if instance_variable_defined?(:@available)
98
+ # Update our available locales.
99
+ @available.replace(@messages.keys.map(&:to_s).sort)
94
100
 
95
101
  # Not only does this clear our cache but it establishes the basic structure
96
102
  # that we rely on in other methods.
97
- @cache = {}
103
+ @cache.clear
98
104
 
99
105
  @messages.each_key do |key|
100
106
  @cache[key] = { false => {}, true => {} }
@@ -106,7 +112,8 @@ class Tater
106
112
  # @param locale [String]
107
113
  # The locale code to set as our default.
108
114
  def locale=(locale)
109
- @locale = locale.to_s if available?(locale)
115
+ str = locale.to_s
116
+ @locale = str if available?(str)
110
117
  end
111
118
 
112
119
  # Localize an Array, Date, Time, DateTime, or Numeric object.
data/test/tater_test.rb CHANGED
@@ -455,4 +455,32 @@ describe Tater do
455
455
  refute i18n.includes?('cascade.nope.tacos', cascade: false)
456
456
  end
457
457
  end
458
+
459
+ describe '#inspect' do
460
+ it 'returns a stringified version of the object' do
461
+ obj = Tater.new(path: File.expand_path('test/fixtures'), locale: 'en')
462
+ assert_equal %(#<Tater:#{ obj.object_id } @cascade=#{ obj.cascades? } @locale="#{ obj.locale }" @available=#{ obj.available }>), obj.inspect
463
+ end
464
+ end
465
+
466
+ describe '#freeze' do
467
+ it 'can be frozen' do
468
+ obj = Tater.new(path: File.expand_path('test/fixtures'), locale: 'en')
469
+ obj.freeze
470
+
471
+ assert obj.includes?('deep')
472
+ assert_equal 'This key is deeper', obj.translate('deep.key')
473
+ assert_equal %w[delimiter_only en fr separator_only], obj.available
474
+
475
+ assert obj.frozen?
476
+ end
477
+
478
+ it 'throws an error if modified after being frozen' do
479
+ obj = Tater.new(path: File.expand_path('test/fixtures'), locale: 'en')
480
+ obj.freeze
481
+
482
+ assert_raises(FrozenError) { obj.locale = 'en' }
483
+ assert_raises(FrozenError) { obj.load(messages: { more: 'Messages' }) }
484
+ end
485
+ end
458
486
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tater
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.4
4
+ version: 3.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Lecklider
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-22 00:00:00.000000000 Z
11
+ date: 2022-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -135,6 +135,7 @@ files:
135
135
  - lib/tater/aliases.rb
136
136
  - lib/tater/hash.rb
137
137
  - lib/tater/utils.rb
138
+ - lib/tater/version.rb
138
139
  - test/fixtures/another.yml
139
140
  - test/fixtures/fixtures.yml
140
141
  - test/fixtures/messages/more.yml
@@ -162,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
163
  - !ruby/object:Gem::Version
163
164
  version: '2.0'
164
165
  requirements: []
165
- rubygems_version: 3.2.32
166
+ rubygems_version: 3.3.7
166
167
  signing_key:
167
168
  specification_version: 4
168
169
  summary: Minimal internationalization and localization library.