Class: Halation::Config
- Inherits:
-
Object
- Object
- Halation::Config
- Defined in:
- lib/halation/config.rb,
lib/halation/config/lens.rb,
lib/halation/config/camera.rb
Overview
Application-wide configuraton.
Defined Under Namespace
Constant Summary collapse
- DEFAULT_CONFIG_PATH =
:nodoc:
File.("~/.halation/config.yml").freeze
Instance Attribute Summary collapse
-
#artist ⇒ Object
readonly
Returns the value of attribute artist.
-
#cameras ⇒ Object
readonly
Returns the value of attribute cameras.
-
#copyright ⇒ Object
readonly
Returns the value of attribute copyright.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#load_file(file_path = nil) ⇒ Object
Load the configuration from a YAML file.
-
#reset ⇒ Object
Reset the configuration to default values.
-
#to_s ⇒ String
List of configuration settings.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
15 16 17 |
# File 'lib/halation/config.rb', line 15 def initialize reset end |
Instance Attribute Details
#artist ⇒ Object (readonly)
Returns the value of attribute artist.
11 12 13 |
# File 'lib/halation/config.rb', line 11 def artist @artist end |
#cameras ⇒ Object (readonly)
Returns the value of attribute cameras.
13 14 15 |
# File 'lib/halation/config.rb', line 13 def cameras @cameras end |
#copyright ⇒ Object (readonly)
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.("./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 |
#reset ⇒ Object
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_s ⇒ String
Returns 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 |