Class: Reap::Project::Settings
Overview
Configuration is an open hash.
TODO: Settings needs improvement – it’s rather sloppy at this point.
Constant Summary collapse
- DEFAULT_FILE =
File.join(File.dirname(__FILE__), 'default.yaml')
- REAP_FILE =
'{.reap,_reap,reapfile}{.yaml,.yml,}'
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data, metadata) ⇒ Settings
constructor
FIXME: when using the settings, I think nil should be considered a none entry and so false would be required to actually mean “off”.
-
#method_missing(s, *a) ⇒ Object
open hash.
Methods included from Extensions::Hash
#argumentize, #to_console, #to_ostruct
Constructor Details
#initialize(data, metadata) ⇒ Settings
FIXME: when using the settings, I think nil should be considered a none entry and so false would be required to actually mean “off”. This means assigning each key value par one a time?
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/reap/settings.rb', line 36 def initialize(data, ) super() @metadata = defaults = File.read(DEFAULT_FILE) defaults = instance_eval("<<-XXXXXXXXXXXXX\n#{defaults}\nXXXXXXXXXXXXX") defaults = YAML::load(defaults) settings = defaults.dup data.each do |key, value| settings[key] ||= {} settings[key].update(value) if value end update(settings) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(s, *a) ⇒ Object
open hash
52 53 54 55 56 57 58 59 60 |
# File 'lib/reap/settings.rb', line 52 def method_missing(s, *a) if s =~ /=$/ self[s] = a[0] elsif a.empty? self[s] else super end end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
31 32 33 |
# File 'lib/reap/settings.rb', line 31 def @metadata end |
Class Method Details
.read(location, metadata) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/reap/settings.rb', line 14 def self.read(location, ) if File.file?(location) file = location else file = Dir.glob(File.join(location, REAP_FILE), File::FNM_CASEFOLD).first end if file data = YAML::load(File.open(file)) || {} else data = {} end new(data, ) end |