Class: Wmctile::Settings

Inherits:
Class
  • Object
show all
Defined in:
lib/wmctile/settings.rb

Instance Method Summary collapse

Methods inherited from Class

#cmd, #notify

Constructor Details

#initializeSettings

Returns a new instance of Settings.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/wmctile/settings.rb', line 8

def initialize
	path = File.expand_path '~/.config/wmctile/wmctile-settings.yml'
	if not File.exist? path
		raw_settings = self.create_new_settings path
	end
	raw_settings ||= File.read path
	settings = YAML.load(raw_settings)
	if settings
		settings.each { |name, value|
			instance_variable_set("@#{name}", value)
			self.class.class_eval { attr_reader name.intern }
		}
	end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



4
5
6
# File 'lib/wmctile/settings.rb', line 4

def method_missing sym, *args, &block
	return false
end

Instance Method Details

#create_new_settings(path) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/wmctile/settings.rb', line 28

def create_new_settings path
	req = self.test_requirements
	unless req.nil? or req.length == 0
		puts <<-eos
You don't have #{ req.join(', ') } installed. Wmctile can't run without that.

To fix this on Ubuntu, run:

sudo apt-get install #{ req.join(' ') }
		eos
		exit
	end
	dir_path = path[/(.*)\/wmctile-settings.yml/, 1]
	if not Dir.exists? dir_path
		Dir.mkdir dir_path
	end
	out_file = File.new path, 'w'
	out_file.puts self.default_settings.to_yaml
	out_file.close
end

#default_settingsObject



48
49
50
51
52
53
54
55
# File 'lib/wmctile/settings.rb', line 48

def default_settings
	{
		:window_border => 1,
		:panel_height => 24,
		:panel_width => 0,
		:hostname => self.cmd('hostname')
	}
end

#test_requirementsObject



23
24
25
26
27
# File 'lib/wmctile/settings.rb', line 23

def test_requirements
	req = ['xrandr', 'wmctrl', 'dmenu']
	ret = req.reject { |r| self.cmd("which #{ r }").length > 0 }
	return ret
end