Class: BinData::BaseArgProcessor
- Inherits:
-
Object
- Object
- BinData::BaseArgProcessor
- Defined in:
- lib/bindata/base.rb
Overview
ArgProcessors process the arguments passed to BinData::Base.new into the form required to initialise the BinData object.
Any passed parameters are sanitized so the BinData object doesn't need to perform error checking on the parameters.
Direct Known Subclasses
ArrayArgProcessor, BufferArgProcessor, ChoiceArgProcessor, DelayedIoArgProcessor, PrimitiveArgProcessor, SectionArgProcessor, SkipArgProcessor, StringArgProcessor, StructArgProcessor, Uint8ArrayArgProcessor
Constant Summary collapse
- @@empty_hash =
Hash.new.freeze
Instance Method Summary collapse
-
#extract_args(obj_class, obj_args) ⇒ Object
Takes the arguments passed to BinData::Base.new and extracts [value, sanitized_parameters, parent].
-
#sanitize_parameters!(obj_class, obj_params) ⇒ Object
Performs sanity checks on the given parameters.
-
#separate_args(_obj_class, obj_args) ⇒ Object
Separates the arguments passed to BinData::Base.new into [value, parameters, parent].
Instance Method Details
#extract_args(obj_class, obj_args) ⇒ Object
Takes the arguments passed to BinData::Base.new and extracts [value, sanitized_parameters, parent].
296 297 298 299 300 301 |
# File 'lib/bindata/base.rb', line 296 def extract_args(obj_class, obj_args) value, params, parent = separate_args(obj_class, obj_args) sanitized_params = SanitizedParameters.sanitize(params, obj_class) [value, sanitized_params, parent] end |
#sanitize_parameters!(obj_class, obj_params) ⇒ Object
Performs sanity checks on the given parameters. This method converts the parameters to the form expected by the data object.
329 |
# File 'lib/bindata/base.rb', line 329 def sanitize_parameters!(obj_class, obj_params); end |
#separate_args(_obj_class, obj_args) ⇒ Object
Separates the arguments passed to BinData::Base.new into [value, parameters, parent]. Called by #extract_args.
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/bindata/base.rb', line 305 def separate_args(_obj_class, obj_args) args = obj_args.dup value = parameters = parent = nil if args.length > 1 && args.last.is_a?(BinData::Base) parent = args.pop end if args.length > 0 && args.last.is_a?(Hash) parameters = args.pop end if args.length > 0 value = args.pop end parameters ||= @@empty_hash [value, parameters, parent] end |