Sha256: 8f7c03c33c1b87f8c745aee9f05135fdfaf8a1a3b2a061896fa249dae3ec2aa7

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

module Mayl
  # Public: Represents the global state with the loaded locales, and has the
  # ability to save locales to disk.
  class Env
    attr_reader :locales
    attr_accessor :last_value
    attr_accessor :namespace

    # 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.
    def autocomplete(key)
      peek.grep(/^#{Regexp.escape(key)}/)
    end

    # 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.
    def peek(namespace=self.namespace)
      locales.map { |locale| locale.peek(namespace) }.flatten.uniq
    end

    # Public: Initializes a new Env loading the locales from a path.
    def initialize(path)
      @locales    = Loader.load(path)
      @last_value = nil
      @namespace  = ""
    end

    # Public: Saves any changes to disk.
    def commit
      @locales.each(&:commit)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mayl-0.2.1 lib/mayl/env.rb
mayl-0.2.0 lib/mayl/env.rb