Class: Mayl::Env
- Inherits:
-
Object
- Object
- Mayl::Env
- Defined in:
- lib/mayl/env.rb
Overview
Public: Represents the global state with the loaded locales, and has the ability to save locales to disk.
Instance Attribute Summary collapse
-
#last_value ⇒ Object
Returns the value of attribute last_value.
-
#locales ⇒ Object
readonly
Returns the value of attribute locales.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
Instance Method Summary collapse
-
#autocomplete(key) ⇒ Object
Public: Autocompletes a key looking at the current namespace and their contents.
-
#commit ⇒ Object
Public: Saves any changes to disk.
-
#initialize(path) ⇒ Env
constructor
Public: Initializes a new Env loading the locales from a path.
-
#peek(namespace = self.namespace) ⇒ Object
Public: Returns the keys inside a namespace, by default ours.
Constructor Details
Instance Attribute Details
#last_value ⇒ Object
Returns the value of attribute last_value.
6 7 8 |
# File 'lib/mayl/env.rb', line 6 def last_value @last_value end |
#locales ⇒ Object (readonly)
Returns the value of attribute locales.
5 6 7 |
# File 'lib/mayl/env.rb', line 5 def locales @locales end |
#namespace ⇒ Object
Returns the value of attribute namespace.
7 8 9 |
# File 'lib/mayl/env.rb', line 7 def namespace @namespace end |
Instance Method Details
#autocomplete(key) ⇒ Object
Public: Autocompletes a key looking at the current namespace and their contents.
key - the partial key to consult in the namespace.
Returns an Array of results.
15 16 17 |
# File 'lib/mayl/env.rb', line 15 def autocomplete(key) peek.grep(/^#{Regexp.escape(key)}/) end |
#commit ⇒ Object
Public: Saves any changes to disk.
36 37 38 |
# File 'lib/mayl/env.rb', line 36 def commit @locales.each(&:commit) end |
#peek(namespace = self.namespace) ⇒ Object
Public: Returns the keys inside a namespace, by default ours.
namespace - the namespace to peek in. It’s ours by default.
Returns an Array of results.
24 25 26 |
# File 'lib/mayl/env.rb', line 24 def peek(namespace=self.namespace) locales.map { |locale| locale.peek(namespace) }.flatten.uniq end |