Class: Kiseru::Config
- Inherits:
-
Object
- Object
- Kiseru::Config
- Defined in:
- lib/ki_youtrack/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.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ki_youtrack/kiseru.rb', line 38 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.
32 33 34 |
# File 'lib/ki_youtrack/kiseru.rb', line 32 def path @path end |
Class Method Details
Instance Method Details
#ensure_present(*keys) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/ki_youtrack/kiseru.rb', line 49 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
63 64 65 66 67 |
# File 'lib/ki_youtrack/kiseru.rb', line 63 def read(key) @store.transaction(read_only=true) do @store[key] end end |
#write(key, value) ⇒ Object
57 58 59 60 61 |
# File 'lib/ki_youtrack/kiseru.rb', line 57 def write(key, value) @store.transaction do @store[key] = value end end |