Class: AppCfg::Source
- Inherits:
-
Object
- Object
- AppCfg::Source
- Defined in:
- lib/appcfg/source.rb
Direct Known Subclasses
Constant Summary collapse
- @@sources =
[]
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Source
constructor
A new instance of Source.
- #reload_data! ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Source
Returns a new instance of Source.
5 6 7 |
# File 'lib/appcfg/source.rb', line 5 def initialize(={}) @hash = end |
Class Method Details
.add(source_object, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/appcfg/source.rb', line 17 def self.add(source_object, ={}) if source_object.is_a?(String) && source_object[-4..-1] == '.yml' #YAML raise "File #{source_object} could not be located" unless File.exist? source_object add_source(YamlSource.new(.merge(:file => source_object))) elsif source_object.is_a?(Class) && source_object.respond_to?(:all) #AR Model add_source(ModelSource.new(.merge(:class => source_object))) elsif source_object.is_a?(Hash) #Simple hash add_source(Source.new(source_object)) else raise 'Could not match source object to any known types' end end |
.list ⇒ Object
33 34 35 |
# File 'lib/appcfg/source.rb', line 33 def self.list @@sources end |
.reload_sources! ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/appcfg/source.rb', line 37 def self.reload_sources! cache = {} @@sources.each do |source| source.reload_data! cache = cache.merge(source.to_hash) end AppCfg.class_variable_set '@@cache', hash_to_object(cache) end |
Instance Method Details
#reload_data! ⇒ Object
13 14 15 |
# File 'lib/appcfg/source.rb', line 13 def reload_data! #Do nothing end |
#to_hash ⇒ Object
9 10 11 |
# File 'lib/appcfg/source.rb', line 9 def to_hash @hash end |