Class: Wlog::SysConfig
- Inherits:
-
Object
- Object
- Wlog::SysConfig
- Defined in:
- lib/wlog/domain/sys_config.rb
Overview
Instance Attribute Summary collapse
-
#key_value ⇒ Object
readonly
Key value domain object / helper.
Class Method Summary collapse
-
.ansi! ⇒ Object
SET THE SETTINGS TO ANSI!.
-
.ansi? ⇒ Boolean
Are the settings set to ansi?.
-
.get_config(term) ⇒ Object
Get a term from the configuration file.
-
.not_ansi! ⇒ Object
Oh no! The settings are not ansi!.
-
.read_attributes ⇒ Object
Load a hash from a text file.
-
.store_config(term, value) ⇒ Object
Store a term into the configuration file.
-
.string_decorator ⇒ Object
Get the string decorator.
-
.write_attributes(terms) ⇒ Object
terms is a hash -> => :b, :c => :d write each key value to a file like this: a:b c:d …
Instance Method Summary collapse
-
#initialize ⇒ SysConfig
constructor
A new instance of SysConfig.
-
#last_focus ⇒ Object
load the last focused issue.
-
#last_focus=(issue) ⇒ Object
store the last focused issue.
Constructor Details
Instance Attribute Details
#key_value ⇒ Object (readonly)
Key value domain object / helper
95 96 97 |
# File 'lib/wlog/domain/sys_config.rb', line 95 def key_value @key_value end |
Class Method Details
.ansi! ⇒ Object
SET THE SETTINGS TO ANSI!
36 37 38 |
# File 'lib/wlog/domain/sys_config.rb', line 36 def self.ansi! self.store_config('ansi', 'yes') end |
.ansi? ⇒ Boolean
Are the settings set to ansi?
26 27 28 |
# File 'lib/wlog/domain/sys_config.rb', line 26 def self.ansi? self.read_attributes['ansi'] == 'yes' end |
.get_config(term) ⇒ Object
Get a term from the configuration file. Return nil if not found
48 49 50 |
# File 'lib/wlog/domain/sys_config.rb', line 48 def self.get_config(term) self.read_attributes[term] end |
.not_ansi! ⇒ Object
Oh no! The settings are not ansi!
31 32 33 |
# File 'lib/wlog/domain/sys_config.rb', line 31 def self.not_ansi! self.store_config('ansi', 'no') end |
.read_attributes ⇒ Object
Load a hash from a text file.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/wlog/domain/sys_config.rb', line 78 def self.read_attributes include StaticConfigurations FileUtils.touch ConfigFile lines = File.open(ConfigFile, 'r').read.split(/#{$/}/) terms = lines.map{|e| e.split(':')} values = Hash.new(nil) terms.each do |term_tuple| # [term, value] values[term_tuple[0]] = term_tuple[1] end values rescue Errno::ENOENT $stderr.puts "#{self.class.name}: Problem opening file #{ConfigFile}" # Minimum guarantee: disable ansi colors {'ansi' => 'no'} end |
.store_config(term, value) ⇒ Object
Store a term into the configuration file
41 42 43 44 45 |
# File 'lib/wlog/domain/sys_config.rb', line 41 def self.store_config(term,value) values = self.read_attributes values[term] = value self.write_attributes(values) end |
.string_decorator ⇒ Object
Get the string decorator.
53 54 55 56 57 58 59 |
# File 'lib/wlog/domain/sys_config.rb', line 53 def self.string_decorator if self.ansi? WlogString else UncoloredString end end |
.write_attributes(terms) ⇒ Object
terms is a hash -> => :b, :c => :d write each key value to a file like this:
a:b
c:d
...
66 67 68 69 70 71 72 73 74 |
# File 'lib/wlog/domain/sys_config.rb', line 66 def self.write_attributes(terms) include StaticConfigurations str = terms.inject(""){|str,e| str += "#{e[0]}:#{e[1]}#{$/}"} fh = File.open(ConfigFile, 'w') fh.write(str) fh.close rescue Errno::ENOENT $stderr.puts "#{self.class.name}: Problem opening file #{ConfigFile}" end |
Instance Method Details
#last_focus ⇒ Object
load the last focused issue
16 17 18 |
# File 'lib/wlog/domain/sys_config.rb', line 16 def last_focus @key_value.get('last_focus') end |
#last_focus=(issue) ⇒ Object
store the last focused issue
21 22 23 |
# File 'lib/wlog/domain/sys_config.rb', line 21 def last_focus=(issue) @key_value.put!('last_focus', "#{issue}") end |