Class: FilePipeline::FileOperations::LogDataParser
- Inherits:
-
Object
- Object
- FilePipeline::FileOperations::LogDataParser
- Defined in:
- lib/file_pipeline/file_operations/log_data_parser.rb
Overview
This class parses an object that may be a hash, array other object or nil
.
If it is initialized with an array, that array may contain another array, a hash, any objects, or nil
The resulting instance will behave like an array and always have two elements:
-
nil
or an array containing all arguments that are not a hash at index 0 -
nil
or a hash at index 1.
Examples
When passed nil
:
LogDataParser.new(nil).to_a
# => [nil, nil]
When initialized with individual strings or errors, those will be wrapped in an array:
LogDataParser.new(StandardError.new).to_a
# => [[#<StandardError: StandardError>], nil]
LogDataParser.new('a warning').to_a
# => [['a warning'], nil]
This is also true when initialized with individual messages or errors along with data:
LogDataParser.new(['a warning', { a_key: 'some value' }]).to_a
# => [['a warning'], { a_key: 'some value' }]
LogDataParser.new(['a warning', { a_key: 'some value' }, 'error']).to_a
# => [['a warning', 'error'], { a_key: 'some value' }]
When initialized with a hash, the array will be nil
and the hash:
LogDataParser.new(['a warning', { a_key: 'some value' }]).to_a
# => [nil, { a_key: 'some value' }]
When initialized with an arry that does contain neither arrays nor hashes, it will become the first element of the resulting array, with second being nil
.
LogDataParser.new(['a warning', StandardError.new]).to_a
# => [['a warning', #<StandardError: StandardError>], nil]
When initialized with an array containing an array and a hash, the inner array is will be the first element, the hash the second
log = ['a warning', 'another warning']
data = { a_key: 'some value' }
LogDataParser.new([log, data]).to_a
# => [['a warning', 'another warning'], { a_key: 'some value' }]
LogDataParser.new([data, log])
# => [['a warning', 'another warning'], { a_key: 'some value' }]
When initialized with an array containing a hash and nil
LogDataParser.new([nil, data]).to_a
# => [nil, { a_key: 'some value' }]
Class Method Summary collapse
-
.template ⇒ Object
Returns a trwo element array with an empty array and a hash.
Instance Method Summary collapse
-
#initialize(obj) ⇒ LogDataParser
constructor
:args: object.
Constructor Details
#initialize(obj) ⇒ LogDataParser
:args: object
Returns a new instance for object
, which may be nil
, a hash, another object, or an array, that may itself contain a hash, an array, or other objects.
77 78 79 80 81 |
# File 'lib/file_pipeline/file_operations/log_data_parser.rb', line 77 def initialize(obj) @log_data = nil parse obj normalize end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object (private)
90 91 92 93 94 |
# File 'lib/file_pipeline/file_operations/log_data_parser.rb', line 90 def method_missing(method_name, *args, &block) super unless respond_to_missing? method_name.to_sym @log_data.public_send method_name, *args, &block end |
Class Method Details
.template ⇒ Object
Returns a trwo element array with an empty array and a hash.
84 85 86 |
# File 'lib/file_pipeline/file_operations/log_data_parser.rb', line 84 def self.template [[], {}] end |