class Lingo::Config
Attributes
config_file[R]
lang_file[R]
Public Class Methods
new(*args)
click to toggle source
# File lib/lingo/config.rb, line 33 def initialize(*args) @deprecated = Hash.seen @cli, @opts = CLI.new, {} @cli.execute(*args) @cli.options.each { |key, val| @opts[key.to_s] = val } load_config('language', :lang) load_config('config') if r = get('meeting/attendees', 'text_reader') f = @cli.files if i = r['files'] r['files'] = i.strip == '$(files)' ? f : i.split(SEP_RE) elsif !f.empty? r['files'] = f end end end
Public Instance Methods
[](key)
click to toggle source
# File lib/lingo/config.rb, line 61 def [](key) key_to_nodes(key).inject(to_h) { |hash, node| hash[node] } end
[]=(key, val)
click to toggle source
# File lib/lingo/config.rb, line 65 def []=(key, val) nodes = key_to_nodes(key); node = nodes.pop (self[nodes_to_key(nodes)] ||= {})[node] = val end
deprecate(old, new, obj = self, what = :option, ver = Version.next_minor)
click to toggle source
# File lib/lingo/config.rb, line 107 def deprecate(old, new, obj = self, what = :option, ver = Version.next_minor) unless @deprecated[[source = obj.class.name.sub(/\ALingo::/, ''), old]] warn( "DEPRECATION WARNING: #{source} #{what} `#{old}' is deprecated " << "and will be removed in Lingo #{ver}. Please use `#{new}' instead." ) end end
get(key, *names)
click to toggle source
# File lib/lingo/config.rb, line 70 def get(key, *names) val = self[key] while name = names.shift case val when Hash then val = val[name] when Array then val = val.find { |h| k, v = h.dup.shift break v if k == name } else break end end val end
quit(*args)
click to toggle source
# File lib/lingo/config.rb, line 103 def quit(*args) @cli.send(:quit, *args) end
stderr()
click to toggle source
# File lib/lingo/config.rb, line 95 def stderr @cli.stderr end
stdin()
click to toggle source
# File lib/lingo/config.rb, line 87 def stdin @cli.stdin end
stdout()
click to toggle source
# File lib/lingo/config.rb, line 91 def stdout @cli.stdout end
to_h()
click to toggle source
# File lib/lingo/config.rb, line 57 def to_h { 'version' => VERSION }.merge(@opts) end
warn(*msg)
click to toggle source
# File lib/lingo/config.rb, line 99 def warn(*msg) stderr.puts(*msg) end
Private Instance Methods
key_to_nodes(key)
click to toggle source
# File lib/lingo/config.rb, line 118 def key_to_nodes(key) key.downcase.split('/') end
load_config(key, type = key.to_sym)
click to toggle source
# File lib/lingo/config.rb, line 126 def load_config(key, type = key.to_sym) file = Lingo.find(type, @opts[key]) { quit } instance_variable_set("@#{type}_file", file) File.open(file, encoding: ENCODING) { |f| @opts.update(Psych.safe_load(f.read)) } rescue Psych::SyntaxError => err err.message << " (in #{file})" raise end
nodes_to_key(nodes)
click to toggle source
# File lib/lingo/config.rb, line 122 def nodes_to_key(nodes) nodes.join('/') end