Class: Halation::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/halation/config.rb,
lib/halation/config/lens.rb,
lib/halation/config/camera.rb

Overview

Application-wide configuraton.

Defined Under Namespace

Classes: Camera, Lens

Constant Summary collapse

DEFAULT_CONFIG_PATH =

:nodoc:

File.expand_path("~/.halation/config.yml").freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



15
16
17
# File 'lib/halation/config.rb', line 15

def initialize
  reset
end

Instance Attribute Details

#artistObject (readonly)

Returns the value of attribute artist.



11
12
13
# File 'lib/halation/config.rb', line 11

def artist
  @artist
end

#camerasObject (readonly)

Returns the value of attribute cameras.



13
14
15
# File 'lib/halation/config.rb', line 13

def cameras
  @cameras
end

Returns the value of attribute copyright.



12
13
14
# File 'lib/halation/config.rb', line 12

def copyright
  @copyright
end

Instance Method Details

#load_file(file_path = nil) ⇒ Object

Load the configuration from a YAML file.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/halation/config.rb', line 27

def load_file(file_path = nil)
  file_path ||= File.expand_path("./config.yml") if File.exists?("./config.yml")
  file_path ||= DEFAULT_CONFIG_PATH

  reset

  YAML.load_file(file_path).tap do |config|
    @artist = Coerce.string(config["artist"])
    @copyright = Coerce.string(config["copyright"])

    (config["cameras"] || []).each do |camera|
      @cameras << Camera.new(camera)
    end
  end
end

#resetObject

Reset the configuration to default values.



20
21
22
23
24
# File 'lib/halation/config.rb', line 20

def reset
  @artist = nil
  @copyright = nil
  @cameras = []
end

#to_sString

Returns list of configuration settings.

Returns:

  • (String)

    list of configuration settings.



44
45
46
47
48
49
50
# File 'lib/halation/config.rb', line 44

def to_s
  [
    "Artist: #{@artist}",
    "Copyright: #{@copyright}",
    @cameras.map(&:to_s)
  ].join("\n")
end