Class: BinData::DSLMixin::DSLParser
- Inherits:
-
Object
- Object
- BinData::DSLMixin::DSLParser
show all
- 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
Instance Method Summary
collapse
Constructor Details
#initialize(the_class, parser_type) ⇒ DSLParser
Returns a new instance of DSLParser.
63
64
65
66
67
68
69
70
|
# 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
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
118
119
120
121
|
# File 'lib/bindata/dsl.rb', line 118
def method_missing(*args, &block)
ensure_hints
parse_and_append_field(*args, &block)
end
|
Instance Attribute Details
#parser_type ⇒ Object
Returns the value of attribute parser_type.
72
73
74
|
# File 'lib/bindata/dsl.rb', line 72
def parser_type
@parser_type
end
|
Instance Method Details
#dsl_params ⇒ Object
113
114
115
116
|
# 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) ⇒ Object
74
75
76
77
78
79
80
81
|
# 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 ⇒ Object
109
110
111
|
# File 'lib/bindata/dsl.rb', line 109
def fields
@fields ||= SanitizedFields.new(hints, parent_fields)
end
|
#hide(*args) ⇒ Object
98
99
100
101
102
103
104
105
106
107
|
# 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
|
#search_prefix(*args) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# 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
|