Class: Frontman::DataStore
- Inherits:
-
Object
- Object
- Frontman::DataStore
- Extended by:
- T::Sig
- Defined in:
- lib/frontman/data_store.rb
Instance Attribute Summary collapse
-
#base_file_name ⇒ Object
readonly
Returns the value of attribute base_file_name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #flatten ⇒ Object
-
#initialize(path, base_file_name = nil, parent = nil) ⇒ DataStore
constructor
A new instance of DataStore.
- #method_missing(method_id, *arguments, &block) ⇒ Object
- #respond_to_missing?(method_name, _) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(path, base_file_name = nil, parent = nil) ⇒ DataStore
Returns a new instance of DataStore.
21 22 23 24 25 26 27 28 |
# File 'lib/frontman/data_store.rb', line 21 def initialize(path, base_file_name = nil, parent = nil) @path = path @cache = {} @parent = parent @base_file_name = base_file_name load_files end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *arguments, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/frontman/data_store.rb', line 46 def method_missing(method_id, *arguments, &block) method_name = method_id # Make sure we are able to access data files with an array syntax method_name = arguments[0].to_sym if method_id == :[] if @cache.key?(method_name.to_s) cached = @cache[method_name.to_s] if Frontman::App.instance.refresh_data_files cached.refresh if cached.is_a?(Frontman::DataStoreFile) end return cached end # Make sure we forward the access to the data return @cache.public_send(method_name, &block) if @cache.respond_to?(method_name) nil end |
Instance Attribute Details
#base_file_name ⇒ Object (readonly)
Returns the value of attribute base_file_name.
12 13 14 |
# File 'lib/frontman/data_store.rb', line 12 def base_file_name @base_file_name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
12 13 14 |
# File 'lib/frontman/data_store.rb', line 12 def parent @parent end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
12 13 14 |
# File 'lib/frontman/data_store.rb', line 12 def path @path end |
Instance Method Details
#flatten ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/frontman/data_store.rb', line 31 def flatten elements = [] @cache.sort_by { |_k, v| v.path }.each do |_k, v| if v.instance_of?(Frontman::DataStoreFile) v.refresh elements.push(v) else elements.push(*v.flatten) end end elements end |
#respond_to_missing?(method_name, _) ⇒ Boolean
68 69 70 |
# File 'lib/frontman/data_store.rb', line 68 def respond_to_missing?(method_name, _) @cache.key?(method_name.to_s) || @cache.respond_to?(method_name) end |
#to_s ⇒ Object
73 74 75 |
# File 'lib/frontman/data_store.rb', line 73 def to_s "<DataStore #{@cache.keys.join(', ')} >" end |