Class: LearnLab::Configuration
- Inherits:
-
Object
- Object
- LearnLab::Configuration
- Defined in:
- lib/learn_lab/configuration.rb
Overview
Interface for dealing with persisted configuration file in YAML format.
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#fs ⇒ Object
readonly
Returns the value of attribute fs.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path, data, **options) ⇒ Configuration
constructor
A new instance of Configuration.
- #save! ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
permalink #initialize(path, data, **options) ⇒ Configuration
Returns a new instance of Configuration.
20 21 22 23 24 |
# File 'lib/learn_lab/configuration.rb', line 20 def initialize(path, data, **) @path = path @fs = .fetch(:fs) { LearnLab.file_system } @email = data[:email] end |
Instance Attribute Details
permalink #email ⇒ Object
Returns the value of attribute email.
8 9 10 |
# File 'lib/learn_lab/configuration.rb', line 8 def email @email end |
permalink #fs ⇒ Object (readonly)
Returns the value of attribute fs.
7 8 9 |
# File 'lib/learn_lab/configuration.rb', line 7 def fs @fs end |
permalink #path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/learn_lab/configuration.rb', line 7 def path @path end |
Class Method Details
permalink .open(filename = 'enterprise.yml', **options) ⇒ Object
[View source]
10 11 12 13 14 15 16 17 18 |
# File 'lib/learn_lab/configuration.rb', line 10 def self.open(filename='enterprise.yml', **) fs = .fetch(:fs) { LearnLab.file_system } path = fs.join(fs.home, '.flatiron-school', filename) data = fs.read_yaml_file(path) new(path, data) rescue ConfigurationError path = fs.join(fs.home, '.flatiron-school', 'enterprise.yml') new(path, {}) end |
Instance Method Details
permalink #save! ⇒ Object
[View source]
26 27 28 29 30 |
# File 'lib/learn_lab/configuration.rb', line 26 def save! directory = fs.dirname(path) fs.mkdir(directory) unless fs.directory?(directory) fs.write_yaml_file(path, payload, mode: 'w') end |
permalink #valid? ⇒ Boolean
32 33 34 |
# File 'lib/learn_lab/configuration.rb', line 32 def valid? !email.nil? end |