Class: Biosphere::Settings
- Inherits:
-
Object
- Object
- Biosphere::Settings
- Defined in:
- lib/biosphere/settings.rb
Instance Attribute Summary collapse
-
#feature_manifests ⇒ Object
Returns the value of attribute feature_manifests.
-
#path ⇒ Object
Returns the value of attribute path.
-
#settings ⇒ Object
Returns the value of attribute settings.
Class Method Summary collapse
- .add_feature_manifest(feature, manifests = nil) ⇒ Object
- .class_attribute(*attrs) ⇒ Object
- .class_attributes ⇒ Object
- .feature_manifests(feature = nil) ⇒ Object
-
.find_files(p) ⇒ Object
Finds files from relative path.
- .inherited(subclass) ⇒ Object
- .path ⇒ Object
- .set_feature_manifests(obj) ⇒ Object
- .settings(settings = nil) ⇒ Object
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(settings = {}) ⇒ Settings
constructor
A new instance of Settings.
Constructor Details
#initialize(settings = {}) ⇒ Settings
Returns a new instance of Settings.
99 100 101 102 103 104 105 106 |
# File 'lib/biosphere/settings.rb', line 99 def initialize(settings = {}) @settings = DeepDup.deep_dup(self.class.settings_hash) @feature_manifests = DeepDup.deep_dup(self.class.feature_manifests_hash) @path = self.class.path if settings @settings.deep_merge!(settings) end end |
Instance Attribute Details
#feature_manifests ⇒ Object
Returns the value of attribute feature_manifests.
97 98 99 |
# File 'lib/biosphere/settings.rb', line 97 def feature_manifests @feature_manifests end |
#path ⇒ Object
Returns the value of attribute path.
97 98 99 |
# File 'lib/biosphere/settings.rb', line 97 def path @path end |
#settings ⇒ Object
Returns the value of attribute settings.
97 98 99 |
# File 'lib/biosphere/settings.rb', line 97 def settings @settings end |
Class Method Details
.add_feature_manifest(feature, manifests = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/biosphere/settings.rb', line 46 def add_feature_manifest(feature, manifests=nil) if manifests if !manifests.is_a?(Array) manifests = [manifests] end c = @feature_manifests_hash ||= ::Hash.new c = DeepDup.deep_dup(c) a = (c[feature] ||= ::Array.new) c[feature] = (a + manifests).uniq @feature_manifests_hash = c end return feature_manifests(feature) end |
.class_attribute(*attrs) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/biosphere/settings.rb', line 9 def class_attribute(*attrs) singleton_class.class_eval do attr_accessor(*attrs) end class_attributes.merge(attrs) end |
.class_attributes ⇒ Object
17 18 19 |
# File 'lib/biosphere/settings.rb', line 17 def class_attributes @class_attributes ||= ::Set.new end |
.feature_manifests(feature = nil) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/biosphere/settings.rb', line 66 def feature_manifests(feature=nil) if feature if @feature_manifests_hash return @feature_manifests_hash[feature] else return nil end else return @feature_manifests_hash end end |
.find_files(p) ⇒ Object
Finds files from relative path
83 84 85 86 87 88 89 90 |
# File 'lib/biosphere/settings.rb', line 83 def find_files(p) if !$current_biosphere_path_stack $current_biosphere_path_stack = "." end relative_path = $current_biosphere_path_stack + "/" + p entries = Dir[(relative_path)] - [".", ".."] return entries end |
.inherited(subclass) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/biosphere/settings.rb', line 21 def inherited(subclass) class_attributes.each do |attr| value = send(attr) value = DeepDup.deep_dup(value) # rescue value subclass.class_attribute attr subclass.send("#{attr}=", value) p = path if p != "" p = p + "/" end subclass.send("path=", p + subclass.name.split('::').last) end end |
.path ⇒ Object
78 79 80 |
# File 'lib/biosphere/settings.rb', line 78 def path() return @path end |
.set_feature_manifests(obj) ⇒ Object
62 63 64 |
# File 'lib/biosphere/settings.rb', line 62 def set_feature_manifests(obj) @feature_manifests_hash = obj end |
.settings(settings = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/biosphere/settings.rb', line 36 def settings(settings=nil) if settings c = @settings_hash ||= ::Hash.new c = DeepDup.deep_dup(c) c.deep_merge!(settings, {:overwrite_arrays => true}) @settings_hash = c end return @settings_hash end |
Instance Method Details
#[](key) ⇒ Object
108 109 110 |
# File 'lib/biosphere/settings.rb', line 108 def [](key) return @settings[key] end |