Class: BinData::DSLMixin::DSLFieldParser
- Inherits:
-
Object
- Object
- BinData::DSLMixin::DSLFieldParser
- Defined in:
- lib/bindata/dsl.rb
Overview
Extracts the details from a field declaration.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(namespace, hints, symbol, *args, &block) ⇒ DSLFieldParser
constructor
A new instance of DSLFieldParser.
- #name_from_field_declaration(args) ⇒ Object
- #params_from_args(args) ⇒ Object
- #params_from_block(&block) ⇒ Object
- #params_from_field_declaration(args, &block) ⇒ Object
Constructor Details
#initialize(namespace, hints, symbol, *args, &block) ⇒ DSLFieldParser
Returns a new instance of DSLFieldParser.
364 365 366 367 368 369 370 |
# File 'lib/bindata/dsl.rb', line 364 def initialize(namespace, hints, symbol, *args, &block) @namespace = namespace @hints = hints @type = symbol @name = name_from_field_declaration(args) @params = params_from_field_declaration(args, &block) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
372 373 374 |
# File 'lib/bindata/dsl.rb', line 372 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
372 373 374 |
# File 'lib/bindata/dsl.rb', line 372 def params @params end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
372 373 374 |
# File 'lib/bindata/dsl.rb', line 372 def type @type end |
Instance Method Details
#name_from_field_declaration(args) ⇒ Object
374 375 376 377 378 379 380 381 |
# File 'lib/bindata/dsl.rb', line 374 def name_from_field_declaration(args) name, _ = args if name == "" || name.is_a?(Hash) nil else name end end |
#params_from_args(args) ⇒ Object
393 394 395 396 397 398 |
# File 'lib/bindata/dsl.rb', line 393 def params_from_args(args) name, params = args params = name if name.is_a?(Hash) params || {} end |
#params_from_block(&block) ⇒ Object
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/bindata/dsl.rb', line 400 def params_from_block(&block) bindata_classes = { array: BinData::Array, buffer: BinData::Buffer, choice: BinData::Choice, delayed_io: BinData::DelayedIO, section: BinData::Section, skip: BinData::Skip, struct: BinData::Struct } if bindata_classes.include?(@type) parser = DSLParser.new(bindata_classes[@type], @type) parser.namespace = @namespace parser.endian(@hints[:endian]) parser.search_namespace(*@hints[:search_namespace]) parser.search_prefix(*@hints[:search_prefix]) parser.instance_eval(&block) parser.dsl_params else {} end end |
#params_from_field_declaration(args, &block) ⇒ Object
383 384 385 386 387 388 389 390 391 |
# File 'lib/bindata/dsl.rb', line 383 def params_from_field_declaration(args, &block) params = params_from_args(args) if block_given? params.merge(params_from_block(&block)) else params end end |