Class: PufferPages::Backends::Mixins::Localable::Locales
- Inherits:
-
ActiveSupport::HashWithIndifferentAccess
- Object
- ActiveSupport::HashWithIndifferentAccess
- PufferPages::Backends::Mixins::Localable::Locales
- Defined in:
- lib/puffer_pages/backends/models/mixins/localable.rb
Class Method Summary collapse
Instance Method Summary collapse
- #error ⇒ Object
-
#initialize(source) ⇒ Locales
constructor
A new instance of Locales.
- #translations ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(source) ⇒ Locales
Returns a new instance of Locales.
21 22 23 24 |
# File 'lib/puffer_pages/backends/models/mixins/localable.rb', line 21 def initialize source update (source.presence || {}).stringify_keys super() end |
Class Method Details
Instance Method Details
#error ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/puffer_pages/backends/models/mixins/localable.rb', line 30 def error translations rescue ::SyntaxError => e e. else false end |
#translations ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/puffer_pages/backends/models/mixins/localable.rb', line 38 def translations @translations ||= Hash[map do |(locale, yaml)| load_arguments = [yaml] load_arguments.push "<#{locale}>" if YAML.method(:load).arity == -2 result = YAML.load yaml result = result.presence || {} raise ::SyntaxError.new("(<#{locale}>): Locale should be a hash") unless result.is_a?(Hash) [locale.to_sym, result.deep_symbolize_keys] end] end |
#valid? ⇒ Boolean
26 27 28 |
# File 'lib/puffer_pages/backends/models/mixins/localable.rb', line 26 def valid? !error end |