Class: BinData::DSLMixin::DSLParser
- Inherits:
-
Object
- Object
- BinData::DSLMixin::DSLParser
- Defined in:
- lib/bindata/dsl.rb
Overview
A DSLParser parses and accumulates field definitions of the form
type name, params
where:
* +type+ is the under_scored name of a registered type
* +name+ is the (possible optional) name of the field
* +params+ is a hash containing any parameters
Instance Attribute Summary collapse
-
#parser_type ⇒ Object
readonly
Returns the value of attribute parser_type.
Instance Method Summary collapse
- #dsl_params ⇒ Object
- #endian(endian = nil) ⇒ Object
- #fields ⇒ Object
- #hide(*args) ⇒ Object
-
#initialize(the_class, parser_type) ⇒ DSLParser
constructor
A new instance of DSLParser.
-
#method_missing(symbol, *args, &block) ⇒ Object
:nodoc:.
Constructor Details
#initialize(the_class, parser_type) ⇒ DSLParser
Returns a new instance of DSLParser.
36 37 38 39 40 |
# File 'lib/bindata/dsl.rb', line 36 def initialize(the_class, parser_type) @the_class = the_class @parser_type = parser_type @endian = parent_attribute(:endian, nil) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
:nodoc:
97 98 99 100 101 102 103 |
# File 'lib/bindata/dsl.rb', line 97 def method_missing(symbol, *args, &block) #:nodoc: type = symbol name = name_from_field_declaration(args) params = params_from_field_declaration(type, args, &block) append_field(type, name, params) end |
Instance Attribute Details
#parser_type ⇒ Object (readonly)
Returns the value of attribute parser_type.
42 43 44 |
# File 'lib/bindata/dsl.rb', line 42 def parser_type @parser_type end |
Instance Method Details
#dsl_params ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/bindata/dsl.rb', line 82 def dsl_params case @parser_type when :struct to_struct_params when :array to_array_params when :choice to_choice_params when :primitive to_struct_params else raise "unknown parser type #{@parser_type}" end end |
#endian(endian = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/bindata/dsl.rb', line 44 def endian(endian = nil) if endian.nil? @endian elsif endian == :big or endian == :little @endian = endian else dsl_raise ArgumentError, "unknown value for endian '#{endian}'" end end |
#fields ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/bindata/dsl.rb', line 72 def fields unless defined? @fields fields = parent_attribute(:fields, nil) @fields = SanitizedFields.new(endian) @fields.copy_fields(fields) if fields end @fields end |
#hide(*args) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/bindata/dsl.rb', line 54 def hide(*args) if option?(:hidden_fields) hidden = args.collect do |name| unless Symbol === name warn "Hidden field '#{name}' should be provided as a symbol. Using strings is deprecated" end name.to_sym end unless defined? @hide @hide = parent_attribute(:hide, []).dup end @hide.concat(hidden.compact) @hide end end |