class Cronex::Resource

Attributes

locale[R]
messages[R]

Public Class Methods

new(loc = :en) click to toggle source
# File lib/cronex/resource.rb, line 8
def initialize(loc = :en)
  self.locale = loc || :en
end

Public Instance Methods

[](key) click to toggle source
# File lib/cronex/resource.rb, line 28
def [](key)
  @messages[key]
end
Also aliased as: get
get(key)
Alias for: []
load(loc) click to toggle source
# File lib/cronex/resource.rb, line 22
def load(loc)
  file = File.join(RESOURCES_DIR,  "resources_#{loc}.yml")
  fail ResourceError, "Resource file #{file} for '#{loc}' locale not found" unless File.exist?(file)
  YAML.load_file(file)
end
locale=(loc) click to toggle source
# File lib/cronex/resource.rb, line 12
def locale=(loc)
  result = load(loc)
  if result.nil? || result.empty?
    fail ResourceError, "Error: Invalid resource file for '#{loc}' locale"
  else
    @locale = loc
    @messages = result
  end
end