class BinData::DSLMixin::DSLParser

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

Attributes

parser_type[R]

Public Class Methods

new(the_class, parser_type) click to toggle source
# File lib/bindata/dsl.rb, line 63
def initialize(the_class, parser_type)
  raise "unknown parser type #{parser_type}" unless parser_abilities[parser_type]

  @the_class      = the_class
  @parser_type    = parser_type
  @validator      = DSLFieldValidator.new(the_class, self)
  @endian         = nil
end

Public Instance Methods

dsl_params() click to toggle source
# File lib/bindata/dsl.rb, line 113
def dsl_params
  abilities = parser_abilities[@parser_type]
  send(abilities.at(0), abilities.at(1))
end
endian(endian = nil) click to toggle source
# File lib/bindata/dsl.rb, line 74
def endian(endian = nil)
  if endian
    set_endian(endian)
  elsif @endian.nil?
    set_endian(parent_attribute(:endian))
  end
  @endian
end
fields() click to toggle source
# File lib/bindata/dsl.rb, line 109
def fields
  @fields ||= SanitizedFields.new(hints, parent_fields)
end
hide(*args) click to toggle source
# File lib/bindata/dsl.rb, line 98
def hide(*args)
  if option?(:hidden_fields)
    @hide ||= parent_attribute(:hide, []).dup

    hidden = args.collect(&:to_sym).compact
    @hide.concat(hidden)

    @hide
  end
end
method_missing(*args, &block) click to toggle source
# File lib/bindata/dsl.rb, line 118
def method_missing(*args, &block)
  ensure_hints
  parse_and_append_field(*args, &block)
end
search_prefix(*args) click to toggle source
# File lib/bindata/dsl.rb, line 83
def search_prefix(*args)
  @search_prefix ||= parent_attribute(:search_prefix, []).dup

  prefix = args.collect(&:to_sym).compact
  unless prefix.empty?
    if fields?
      dsl_raise SyntaxError, "search_prefix must be called before defining fields"
    end

    @search_prefix = prefix.concat(@search_prefix)
  end

  @search_prefix
end