Module: BinData::MultiFieldArgSeparator
- Included in:
- BufferArgProcessor, DelayedIoArgProcessor, RecordArgProcessor, SectionArgProcessor
- Defined in:
- lib/bindata/dsl.rb
Overview
Extracts args for Records and Buffers.
Foo.new(bar: “baz) is ambiguous as to whether :bar is a value or parameter.
BaseArgExtractor always assumes :bar is parameter. This extractor correctly identifies it as value or parameter.
Instance Method Summary collapse
- #field_names_in_parameters?(obj_class, parameters) ⇒ Boolean
- #parameters_is_value?(obj_class, value, parameters) ⇒ Boolean
- #separate_args(obj_class, obj_args) ⇒ Object
Instance Method Details
#field_names_in_parameters?(obj_class, parameters) ⇒ Boolean
28 29 30 31 32 33 |
# File 'lib/bindata/dsl.rb', line 28 def field_names_in_parameters?(obj_class, parameters) field_names = obj_class.fields.field_names param_keys = parameters.keys !(field_names & param_keys).empty? end |
#parameters_is_value?(obj_class, value, parameters) ⇒ Boolean
20 21 22 23 24 25 26 |
# File 'lib/bindata/dsl.rb', line 20 def parameters_is_value?(obj_class, value, parameters) if value.nil? && !parameters.empty? field_names_in_parameters?(obj_class, parameters) else false end end |
#separate_args(obj_class, obj_args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/bindata/dsl.rb', line 9 def separate_args(obj_class, obj_args) value, parameters, parent = super(obj_class, obj_args) if parameters_is_value?(obj_class, value, parameters) value = parameters parameters = {} end [value, parameters, parent] end |