Class: Scribo::DataDrop
- Inherits:
-
ApplicationDrop
- Object
- Liquid::Drop
- ApplicationDrop
- Scribo::DataDrop
- Defined in:
- app/drops/scribo/data_drop.rb
Instance Attribute Summary collapse
-
#data_path ⇒ Object
Returns the value of attribute data_path.
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#initialize(object, data_path = []) ⇒ DataDrop
constructor
A new instance of DataDrop.
- #method_missing(method) ⇒ Object
Constructor Details
#initialize(object, data_path = []) ⇒ DataDrop
Returns a new instance of DataDrop.
10 11 12 13 |
# File 'app/drops/scribo/data_drop.rb', line 10 def initialize(object, data_path = []) @object = object @data_path = data_path end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/drops/scribo/data_drop.rb', line 19 def method_missing(method) content = @object.contents.data((data_path + [method.to_s]).join('/')).first return Scribo::DataDrop.new(@object, data_path + [content.path]) if content&.kind == 'folder' case content&.content_type when 'text/x-yaml' Scribo::Utility.yaml_safe_parse(content.data) when 'application/json' ::JSON.parse(content.data) when 'text/csv' CSV.parse(content.data, headers: true, liberal_parsing: true, quote_char: '"', col_sep: ';', row_sep: "\r\n").map(&:to_h) end end |
Instance Attribute Details
#data_path ⇒ Object
Returns the value of attribute data_path.
8 9 10 |
# File 'app/drops/scribo/data_drop.rb', line 8 def data_path @data_path end |
Instance Method Details
#[](name) ⇒ Object
15 16 17 |
# File 'app/drops/scribo/data_drop.rb', line 15 def [](name) method_missing(name) end |