Class: Jdt::Config
- Inherits:
-
Object
- Object
- Jdt::Config
- Defined in:
- lib/jdt/config.rb
Instance Method Summary collapse
- #directory ⇒ Object
-
#initialize(file) ⇒ Config
constructor
A new instance of Config.
- #update {|props| ... } ⇒ Object
- #yaml_file ⇒ Object
- #yaml_props ⇒ Object
Constructor Details
#initialize(file) ⇒ Config
Returns a new instance of Config.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/jdt/config.rb', line 7 def initialize(file) # ensure that folder exists if (not File.exists?(directory)) FileUtils.makedirs(directory) end @file = file # ensure that file exist if (not File.exists?(yaml_file)) File.open(yaml_file, "w") do |f| f << "\#YAML file for storing configuration information" end end end |
Instance Method Details
#directory ⇒ Object
24 25 26 |
# File 'lib/jdt/config.rb', line 24 def directory "#{ENV['HOME']}/.jdt" end |
#update {|props| ... } ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jdt/config.rb', line 41 def update # read props = yaml_props # change yield props # write File.open(yaml_file, "w") do |f| f << props.to_yaml end end |
#yaml_file ⇒ Object
28 29 30 |
# File 'lib/jdt/config.rb', line 28 def yaml_file "#{directory}/#{@file}" end |
#yaml_props ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/jdt/config.rb', line 32 def yaml_props props = YAML.load_file(yaml_file) if (props) props else Hash.new end end |