Class: Barabara::Configuration

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

Overview

Load configuration from a file and store it as an object.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file) ⇒ Configuration

Returns a new instance of Configuration.



13
14
15
16
17
18
# File 'lib/barabara/config.rb', line 13

def initialize(config_file)
  @config = YAML.load_file config_file
  @modules = parse_module_list(@config['modules'])
  @session  = ENV['XDG_SESSION_DESKTOP']
  @monitors = Modules::WM.get_monitors(@session)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/barabara/config.rb', line 11

def config
  @config
end

#modulesObject (readonly)

Returns the value of attribute modules.



11
12
13
# File 'lib/barabara/config.rb', line 11

def modules
  @modules
end

#monitorsObject (readonly)

Returns the value of attribute monitors.



11
12
13
# File 'lib/barabara/config.rb', line 11

def monitors
  @monitors
end

#sessionObject (readonly)

Returns the value of attribute session.



11
12
13
# File 'lib/barabara/config.rb', line 11

def session
  @session
end

Class Method Details

.dump_default_config(path) ⇒ Object



29
30
31
32
33
# File 'lib/barabara/config.rb', line 29

def self.dump_default_config(path)
  File.open(File.expand_path(path), 'w') do |f|
    f.write default_config.to_yaml
  end
end

Instance Method Details

#colorsObject



20
# File 'lib/barabara/config.rb', line 20

def colors; @config['colors']; end

#module_config(mod_name) ⇒ Object



23
24
25
26
27
# File 'lib/barabara/config.rb', line 23

def module_config(mod_name)
  return {} unless module_options.key?(mod_name)

  module_options[mod_name]
end

#module_optionsObject



21
# File 'lib/barabara/config.rb', line 21

def module_options; @config['module_options']; end