Class: Fare::LoadConfigurationFile
- Inherits:
-
Object
- Object
- Fare::LoadConfigurationFile
- Defined in:
- lib/fare/load_configuration_file.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #add_lib_dir_to_load_path ⇒ Object
- #checksum ⇒ Object
- #code ⇒ Object
- #configuration ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(options) ⇒ LoadConfigurationFile
constructor
A new instance of LoadConfigurationFile.
- #load_configuration ⇒ Object
- #lock_filename ⇒ Object
- #verify_file! ⇒ Object
Constructor Details
#initialize(options) ⇒ LoadConfigurationFile
Returns a new instance of LoadConfigurationFile.
6 7 8 9 10 |
# File 'lib/fare/load_configuration_file.rb', line 6 def initialize() @filename = .fetch(:filename) { Fare.default_config_file } @environment = .fetch(:environment) { Fare.environment } verify_file! end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
4 5 6 |
# File 'lib/fare/load_configuration_file.rb', line 4 def environment @environment end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
4 5 6 |
# File 'lib/fare/load_configuration_file.rb', line 4 def filename @filename end |
Instance Method Details
#add_lib_dir_to_load_path ⇒ Object
45 46 47 48 49 50 |
# File 'lib/fare/load_configuration_file.rb', line 45 def add_lib_dir_to_load_path lib_dir = File.("../../lib", filename) if File.directory?(lib_dir) && !$LOAD_PATH.include?(lib_dir) $LOAD_PATH.unshift(lib_dir) end end |
#checksum ⇒ Object
37 38 39 |
# File 'lib/fare/load_configuration_file.rb', line 37 def checksum Digest::MD5.hexdigest(code) end |
#code ⇒ Object
29 30 31 |
# File 'lib/fare/load_configuration_file.rb', line 29 def code @code ||= File.open(filename.to_s, "r:utf-8").read end |
#configuration ⇒ Object
18 19 20 |
# File 'lib/fare/load_configuration_file.rb', line 18 def configuration @configuration ||= load_configuration end |
#exists? ⇒ Boolean
41 42 43 |
# File 'lib/fare/load_configuration_file.rb', line 41 def exists? File.exist?(filename) end |
#load_configuration ⇒ Object
22 23 24 25 26 27 |
# File 'lib/fare/load_configuration_file.rb', line 22 def load_configuration add_lib_dir_to_load_path dsl = ConfigurationDSL.new dsl.instance_eval(code, filename) dsl.configuration end |
#lock_filename ⇒ Object
33 34 35 |
# File 'lib/fare/load_configuration_file.rb', line 33 def lock_filename File.("../fare.#{environment}.lock", filename) end |
#verify_file! ⇒ Object
12 13 14 15 16 |
# File 'lib/fare/load_configuration_file.rb', line 12 def verify_file! unless exists? raise ConfigurationNotFoundError, "Configuration file doesn't exist at #{filename}" end end |