Class: Mode::Config
- Inherits:
-
Object
- Object
- Mode::Config
- Defined in:
- lib/mode/config.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#data_sources ⇒ Object
Returns the value of attribute data_sources.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#username ⇒ Object
Config Variables.
Class Method Summary collapse
- .default_dir ⇒ Object
- .default_filename ⇒ Object
- .drivers_dir ⇒ Object
- .exists?(path) ⇒ Boolean
- .full_path(path, filename = nil) ⇒ Object
- .init(path, filename = nil) ⇒ Object
- .log_dir ⇒ Object
Instance Method Summary collapse
- #access_token_key ⇒ Object
- #access_token_password ⇒ Object
-
#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.
13 14 15 16 17 18 19 20 21 |
# File 'lib/mode/config.rb', line 13 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 |
#data_sources ⇒ Object
Returns the value of attribute data_sources.
11 12 13 |
# File 'lib/mode/config.rb', line 11 def data_sources @data_sources end |
#environment ⇒ Object
Returns the value of attribute environment.
10 11 12 |
# File 'lib/mode/config.rb', line 10 def environment @environment end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/mode/config.rb', line 5 def path @path end |
#username ⇒ Object
Config Variables
8 9 10 |
# File 'lib/mode/config.rb', line 8 def username @username end |
Class Method Details
.default_dir ⇒ Object
59 60 61 |
# File 'lib/mode/config.rb', line 59 def default_dir File.("~/.mode") end |
.default_filename ⇒ Object
38 39 40 |
# File 'lib/mode/config.rb', line 38 def default_filename 'config.yml' end |
.drivers_dir ⇒ Object
67 68 69 |
# File 'lib/mode/config.rb', line 67 def drivers_dir File.join(default_dir, 'drivers') end |
.exists?(path) ⇒ Boolean
42 43 44 |
# File 'lib/mode/config.rb', line 42 def exists?(path) File.exist?(full_path(path)) end |
.full_path(path, filename = nil) ⇒ Object
71 72 73 |
# File 'lib/mode/config.rb', line 71 def full_path(path, filename = nil) File.(File.join(path, filename || default_filename)) end |
.init(path, filename = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/mode/config.rb', line 46 def init(path, filename = nil) FileUtils.mkdir_p(default_dir) FileUtils.mkdir_p(log_dir) FileUtils.mkdir_p(drivers_dir) File.open(full_path(path, filename), 'w+') do |file| file.write({}.to_yaml) end new(path, filename) end |
.log_dir ⇒ Object
63 64 65 |
# File 'lib/mode/config.rb', line 63 def log_dir File.join(default_dir, 'log') end |
Instance Method Details
#access_token_key ⇒ Object
29 30 31 |
# File 'lib/mode/config.rb', line 29 def access_token_key access_token && access_token['token'] end |
#access_token_password ⇒ Object
33 34 35 |
# File 'lib/mode/config.rb', line 33 def access_token_password access_token && access_token['password'] end |
#save ⇒ Object
23 24 25 26 27 |
# File 'lib/mode/config.rb', line 23 def save File.open(path, 'w+') do |file| file.write(to_yaml) end end |