Class: Play::Configuration
- Inherits:
-
Object
- Object
- Play::Configuration
- Defined in:
- lib/play/configuration.rb
Overview
A play configuration. Usually loaded from YAML, configured in Ruby, or
passed on the command line.
Class Attribute Summary collapse
-
.default ⇒ Object
A
Configurationinstance that is referenced when a value is not set.
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
Class Method Summary collapse
-
.dump(path) ⇒ Object
Loads a
Configuration. -
.load(arg) ⇒ Object
Loads a
Configuration.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Retrieves a setting from this
Configuration. -
#[]=(key, value) ⇒ Object
Sets a setting for this
Configuration. -
#initialize(arg = nil) ⇒ Configuration
constructor
Creates a new
Configurationinstance.
Constructor Details
#initialize(arg = nil) ⇒ Configuration
Creates a new Configuration instance.
39 40 41 |
# File 'lib/play/configuration.rb', line 39 def initialize arg = nil @settings = arg || Hash.new end |
Class Attribute Details
.default ⇒ Object
A Configuration instance that is referenced when a value is not set.
12 13 14 |
# File 'lib/play/configuration.rb', line 12 def default @default end |
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
35 36 37 |
# File 'lib/play/configuration.rb', line 35 def settings @settings end |
Class Method Details
.dump(path) ⇒ Object
Loads a Configuration. If given a string, treats it as a file path to a
YAML file from which to load the Configuration; if given a Hash, loads
it directly.
27 28 29 30 31 32 33 |
# File 'lib/play/configuration.rb', line 27 def self.dump path path = File:: path Dir::mkdir File.dirname(path) File.open(path, File::CREAT|File::TRUNC|File::RDWR, 0644) do |f| f.puts YAML::dump(@settings) end end |
.load(arg) ⇒ Object
Loads a Configuration. If given a string, treats it as a file path to a
YAML file from which to load the Configuration; if given a Hash, loads
it directly.
19 20 21 |
# File 'lib/play/configuration.rb', line 19 def self.load arg Configuration.new(arg.is_a?(Hash) ? arg : (YAML.load_file(File. arg) if File.exist?(File. arg))) end |
Instance Method Details
#[](key) ⇒ Object
Retrieves a setting from this Configuration.
45 46 47 |
# File 'lib/play/configuration.rb', line 45 def [] key @settings[key] || (Configuration.default == self ? nil : (Configuration.default.nil? ? nil : Configuration.default[key])) end |
#[]=(key, value) ⇒ Object
Sets a setting for this Configuration.
51 52 53 |
# File 'lib/play/configuration.rb', line 51 def []= key, value @settings[key] = value end |