Class: Mode::Config
- Inherits:
-
Object
- Object
- Mode::Config
- Defined in:
- lib/mode/config.rb
Constant Summary collapse
- FILENAME =
'.mode.yml'
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#path ⇒ Object
Returns the value of attribute path.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path, filename = nil) ⇒ Config
constructor
A new instance of Config.
- #save ⇒ Object
Constructor Details
#initialize(path, filename = nil) ⇒ Config
Returns a new instance of Config.
11 12 13 14 15 16 17 18 19 |
# File 'lib/mode/config.rb', line 11 def initialize(path, filename = nil) @path = self.class.full_path(path, filename) if File.exist?(@path) configure YAML.load_file(@path) else raise "Could not load configuration file from #{@path}" end end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
9 10 11 |
# File 'lib/mode/config.rb', line 9 def access_token @access_token end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/mode/config.rb', line 7 def path @path end |
#username ⇒ Object
Returns the value of attribute username.
9 10 11 |
# File 'lib/mode/config.rb', line 9 def username @username end |
Class Method Details
.full_path(path, filename = nil) ⇒ Object
36 37 38 |
# File 'lib/mode/config.rb', line 36 def full_path(path, filename = nil) File.(File.join(path, filename || Mode::Config::FILENAME)) end |
.init(path, filename = nil) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/mode/config.rb', line 28 def init(path, filename = nil) File.open(full_path(path, filename), 'w+') do |file| file.write({}.to_yaml) end new(path, filename) end |
Instance Method Details
#save ⇒ Object
21 22 23 24 25 |
# File 'lib/mode/config.rb', line 21 def save File.open(path, 'w+') do |file| file.write(to_yaml) end end |