Class: QuickStart::Config

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

Constant Summary collapse

TEMPLATE_PATH =
Pathname.new(File.join(File.dirname(__FILE__), 'templates', 'quick_start'))

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Config

Returns a new instance of Config.



12
13
14
# File 'lib/quick_start/config.rb', line 12

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



8
9
10
# File 'lib/quick_start/config.rb', line 8

def file
  @file
end

Instance Method Details

#create_config!Object



41
42
43
44
# File 'lib/quick_start/config.rb', line 41

def create_config!
  FileUtils.cp(TEMPLATE_PATH, Core.config_path)
  return Core.config_path
end

#executablesObject



32
33
34
# File 'lib/quick_start/config.rb', line 32

def executables
  @executables ||= []
end

#parseObject

firefox = /usr/bin/firefox gnome-terminal = /usr/bin/gnome-terminal, checked thunderbird = /usr/bin/mozilla-thunderbird, unchecked



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/quick_start/config.rb', line 19

def parse
  readlines.each do |line|
    next if line =~ /\s*#/
    name, path_with_options = line.split('=', 2).map! { |arg| arg.strip }
    path, comma_separated_options = path_with_options.split(',', 2).map! { |arg| arg.strip }
    options = {}
    comma_separated_options.split(',').each do |option|
      options[option.to_sym] = true
    end if comma_separated_options
    executables << Executable.new(name, path, options)
  end
end

#readlinesObject



36
37
38
39
# File 'lib/quick_start/config.rb', line 36

def readlines
  config = File.readable?(@file) ? @file : create_config!
  return File.readlines(config)
end