Class: Mayl::Env

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Env

Public: Initializes a new Env loading the locales from a path.



29
30
31
32
33
# File 'lib/mayl/env.rb', line 29

def initialize(path)
  @locales    = Loader.load(path)
  @last_value = nil
  @namespace  = ""
end

Instance Attribute Details

#last_valueObject

Returns the value of attribute last_value.



6
7
8
# File 'lib/mayl/env.rb', line 6

def last_value
  @last_value
end

#localesObject (readonly)

Returns the value of attribute locales.



5
6
7
# File 'lib/mayl/env.rb', line 5

def locales
  @locales
end

#namespaceObject

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

#commitObject

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