Class: Lingo::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/lingo/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Config

Returns a new instance of Config.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/lingo/config.rb', line 34

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

Instance Attribute Details

#config_fileObject (readonly)

Returns the value of attribute config_file.



56
57
58
# File 'lib/lingo/config.rb', line 56

def config_file
  @config_file
end

#lang_fileObject (readonly)

Returns the value of attribute lang_file.



56
57
58
# File 'lib/lingo/config.rb', line 56

def lang_file
  @lang_file
end

Instance Method Details

#[](key) ⇒ Object



62
63
64
# File 'lib/lingo/config.rb', line 62

def [](key)
  key_to_nodes(key).inject(to_h) { |hash, node| hash[node] }
end

#[]=(key, val) ⇒ Object



66
67
68
69
# File 'lib/lingo/config.rb', line 66

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) ⇒ Object



108
109
110
111
112
113
114
115
# File 'lib/lingo/config.rb', line 108

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) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/lingo/config.rb', line 71

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) ⇒ Object



104
105
106
# File 'lib/lingo/config.rb', line 104

def quit(*args)
  @cli.send(:quit, *args)
end

#stderrObject



96
97
98
# File 'lib/lingo/config.rb', line 96

def stderr
  @cli.stderr
end

#stdinObject



88
89
90
# File 'lib/lingo/config.rb', line 88

def stdin
  @cli.stdin
end

#stdoutObject



92
93
94
# File 'lib/lingo/config.rb', line 92

def stdout
  @cli.stdout
end

#to_hObject



58
59
60
# File 'lib/lingo/config.rb', line 58

def to_h
  { 'version' => VERSION }.merge(@opts)
end

#warn(*msg) ⇒ Object



100
101
102
# File 'lib/lingo/config.rb', line 100

def warn(*msg)
  stderr.puts(*msg)
end