Class: Wlog::SysConfig
- Inherits:
-
Object
- Object
- Wlog::SysConfig
- Defined in:
- lib/wlog/domain/sys_config.rb
Overview
Instance Attribute Summary collapse
-
#db ⇒ Object
Returns the value of attribute db.
-
#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(db) ⇒ 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
#db ⇒ Object
Returns the value of attribute db.
62 63 64 |
# File 'lib/wlog/domain/sys_config.rb', line 62 def db @db end |
#key_value ⇒ Object (readonly)
Key value domain object / helper
98 99 100 |
# File 'lib/wlog/domain/sys_config.rb', line 98 def key_value @key_value end |
Class Method Details
.ansi! ⇒ Object
SET THE SETTINGS TO ANSI!
37 38 39 |
# File 'lib/wlog/domain/sys_config.rb', line 37 def self.ansi! self.store_config('ansi', 'yes') end |
.ansi? ⇒ Boolean
Are the settings set to ansi?
27 28 29 |
# File 'lib/wlog/domain/sys_config.rb', line 27 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
49 50 51 |
# File 'lib/wlog/domain/sys_config.rb', line 49 def self.get_config(term) self.read_attributes[term] end |
.not_ansi! ⇒ Object
Oh no! The settings are not ansi!
32 33 34 |
# File 'lib/wlog/domain/sys_config.rb', line 32 def self.not_ansi! self.store_config('ansi', 'no') end |
.read_attributes ⇒ Object
Load a hash from a text file.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/wlog/domain/sys_config.rb', line 81 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
42 43 44 45 46 |
# File 'lib/wlog/domain/sys_config.rb', line 42 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.
54 55 56 57 58 59 60 |
# File 'lib/wlog/domain/sys_config.rb', line 54 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
...
69 70 71 72 73 74 75 76 77 |
# File 'lib/wlog/domain/sys_config.rb', line 69 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
17 18 19 |
# File 'lib/wlog/domain/sys_config.rb', line 17 def last_focus @key_value.get('last_focus') end |
#last_focus=(issue) ⇒ Object
store the last focused issue
22 23 24 |
# File 'lib/wlog/domain/sys_config.rb', line 22 def last_focus=(issue) @key_value.put!('last_focus', "#{issue}") end |