Class: Serenity::Configuration
- Inherits:
-
Object
- Object
- Serenity::Configuration
- Defined in:
- lib/serenity.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #exists?(*args) ⇒ Boolean
- #get(*args) ⇒ Object
-
#initialize(filename) ⇒ Configuration
constructor
A new instance of Configuration.
- #to_hash ⇒ Object
Constructor Details
#initialize(filename) ⇒ Configuration
Returns a new instance of Configuration.
26 27 28 29 |
# File 'lib/serenity.rb', line 26 def initialize(filename) @filename = filename @options = YAML.load_file(filename) end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
24 25 26 |
# File 'lib/serenity.rb', line 24 def filename @filename end |
#options ⇒ Object
Returns the value of attribute options.
24 25 26 |
# File 'lib/serenity.rb', line 24 def @options end |
Instance Method Details
#exists?(*args) ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/serenity.rb', line 35 def exists?(*args) c = missing_option_index = 0 args.each_with_index do |arg, i| if c.is_a?(Hash) && c.has_key?(arg) c = c[arg] else missing_option_index = i c = nil end end c end |
#get(*args) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/serenity.rb', line 52 def get(*args) c = missing_option_index = 0 args.each_with_index do |arg, i| if c.is_a?(Hash) && c.has_key?(arg) c = c[arg] else missing_option_index = i raise "Option not found." end end c rescue $stdout.puts "The following option was not found in #{filename}:" (0..missing_option_index).each do |i| $stdout.puts args[i] end $stdout.puts $stdout.puts "Are you sure #{filename} is up to date?" $stdout.puts raise "Option not found." end |
#to_hash ⇒ Object
31 32 33 |
# File 'lib/serenity.rb', line 31 def to_hash end |