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
# 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
# File lib/bindata/dsl.rb, line 113 def dsl_params abilities = parser_abilities[@parser_type] send(abilities.at(0), abilities.at(1)) end
# 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
# File lib/bindata/dsl.rb, line 109 def fields @fields ||= SanitizedFields.new(hints, parent_fields) end
# 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
# File lib/bindata/dsl.rb, line 118 def method_missing(*args, &block) ensure_hints parse_and_append_field(*args, &block) end
# 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