Class: Fare::LoadConfigurationFile

Inherits:
Object
  • Object
show all
Defined in:
lib/fare/load_configuration_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
  @filename = options.fetch(:filename) { Fare.default_config_file }
  @environment = options.fetch(:environment) { Fare.environment }
  verify_file!
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



4
5
6
# File 'lib/fare/load_configuration_file.rb', line 4

def environment
  @environment
end

#filenameObject (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

#checksumObject



36
37
38
# File 'lib/fare/load_configuration_file.rb', line 36

def checksum
  Digest::MD5.hexdigest(code)
end

#codeObject



28
29
30
# File 'lib/fare/load_configuration_file.rb', line 28

def code
  @code ||= File.open(filename.to_s, "r:utf-8").read
end

#configurationObject



18
19
20
# File 'lib/fare/load_configuration_file.rb', line 18

def configuration
  @configuration ||= load_configuration
end

#exists?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/fare/load_configuration_file.rb', line 40

def exists?
  File.exist?(filename)
end

#load_configurationObject



22
23
24
25
26
# File 'lib/fare/load_configuration_file.rb', line 22

def load_configuration
  dsl = ConfigurationDSL.new
  dsl.instance_eval(code, filename)
  dsl.configuration
end

#lock_filenameObject



32
33
34
# File 'lib/fare/load_configuration_file.rb', line 32

def lock_filename
  File.expand_path("../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