Class: Frontman::DataStoreFile
- Inherits:
-
Object
- Object
- Frontman::DataStoreFile
- Extended by:
- T::Sig
- Defined in:
- lib/frontman/data_store_file.rb
Instance Attribute Summary collapse
-
#base_file_name ⇒ Object
Returns the value of attribute base_file_name.
-
#data ⇒ Object
Returns the value of attribute data.
-
#file_name ⇒ Object
Returns the value of attribute file_name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#path ⇒ Object
Returns the value of attribute path.
-
#position ⇒ Object
Returns the value of attribute position.
Instance Method Summary collapse
- #current_path ⇒ Object
-
#initialize(path, file_name, base_file_name, parent) ⇒ DataStoreFile
constructor
A new instance of DataStoreFile.
- #method_missing(method_id, *arguments, &block) ⇒ Object
- #refresh ⇒ Object
- #respond_to_missing?(method_id, _) ⇒ Boolean
- #to_ostruct ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(path, file_name, base_file_name, parent) ⇒ DataStoreFile
Returns a new instance of DataStoreFile.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/frontman/data_store_file.rb', line 22 def initialize(path, file_name, base_file_name, parent) @path = path @file_name = file_name @base_file_name = base_file_name @parent = parent @data = (YAML.load_file(@path) || {}).to_ostruct @@i ||= 0 @position = @@i @@i += 1 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *arguments, &block) ⇒ Object
34 35 36 |
# File 'lib/frontman/data_store_file.rb', line 34 def method_missing(method_id, *arguments, &block) @data.public_send(method_id, *arguments, &block) end |
Instance Attribute Details
#base_file_name ⇒ Object
Returns the value of attribute base_file_name.
11 12 13 |
# File 'lib/frontman/data_store_file.rb', line 11 def base_file_name @base_file_name end |
#data ⇒ Object
Returns the value of attribute data.
11 12 13 |
# File 'lib/frontman/data_store_file.rb', line 11 def data @data end |
#file_name ⇒ Object
Returns the value of attribute file_name.
11 12 13 |
# File 'lib/frontman/data_store_file.rb', line 11 def file_name @file_name end |
#parent ⇒ Object
Returns the value of attribute parent.
11 12 13 |
# File 'lib/frontman/data_store_file.rb', line 11 def parent @parent end |
#path ⇒ Object
Returns the value of attribute path.
11 12 13 |
# File 'lib/frontman/data_store_file.rb', line 11 def path @path end |
#position ⇒ Object
Returns the value of attribute position.
11 12 13 |
# File 'lib/frontman/data_store_file.rb', line 11 def position @position end |
Instance Method Details
#current_path ⇒ Object
43 44 45 |
# File 'lib/frontman/data_store_file.rb', line 43 def current_path @path end |
#refresh ⇒ Object
48 49 50 51 52 53 |
# File 'lib/frontman/data_store_file.rb', line 48 def refresh return unless Frontman::App.instance.refresh_data_files data = YAML.load_file(@path) || {} @data = data.to_ostruct end |
#respond_to_missing?(method_id, _) ⇒ Boolean
38 39 40 |
# File 'lib/frontman/data_store_file.rb', line 38 def respond_to_missing?(method_id, _) @data.respond_to? method_id end |
#to_ostruct ⇒ Object
61 62 63 |
# File 'lib/frontman/data_store_file.rb', line 61 def to_ostruct self end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/frontman/data_store_file.rb', line 56 def to_s "<DataStoreFile #{@data.keys.join(', ')} >" end |