Class: Kiseru::Config
- Inherits:
-
Object
- Object
- Kiseru::Config
- Defined in:
- lib/ki_trello/kiseru.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #ensure_present(*keys) ⇒ Object
-
#initialize(root_path, app_name) ⇒ Config
constructor
A new instance of Config.
- #read(key) ⇒ Object
- #write(key, value) ⇒ Object
Constructor Details
#initialize(root_path, app_name) ⇒ Config
Returns a new instance of Config.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ki_trello/kiseru.rb', line 41 def initialize(root_path, app_name) @path = (root_path + "#{app_name}.yml").to_s unless File.exists?(@path) FileUtils.touch(@path) FileUtils.chmod(0600, @path) end @store = YAML::Store.new(@path) @store.transaction do end end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
35 36 37 |
# File 'lib/ki_trello/kiseru.rb', line 35 def path @path end |
Class Method Details
Instance Method Details
#ensure_present(*keys) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/ki_trello/kiseru.rb', line 52 def ensure_present(*keys) keys.each do |key| if read(key).nil? raise ConfigError, "'#{key}' is not defined in config" end end end |
#read(key) ⇒ Object
66 67 68 69 70 |
# File 'lib/ki_trello/kiseru.rb', line 66 def read(key) @store.transaction(read_only=true) do @store[key] end end |
#write(key, value) ⇒ Object
60 61 62 63 64 |
# File 'lib/ki_trello/kiseru.rb', line 60 def write(key, value) @store.transaction do @store[key] = value end end |