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
71
72
73
|
# 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
m = /(.*)::([^:].*)/.match(@the_class.name)
@namespace = m ? m[1] : ""
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, **kwargs, &block) ⇒ Object
137
138
139
140
|
# File 'lib/bindata/dsl.rb', line 137
def method_missing(*args, **kwargs, &block)
ensure_hints
parse_and_append_field(*args, **kwargs, &block)
end
|
Instance Attribute Details
#namespace ⇒ Object
Returns the value of attribute namespace.
76
77
78
|
# File 'lib/bindata/dsl.rb', line 76
def namespace
@namespace
end
|
#parser_type ⇒ Object
Returns the value of attribute parser_type.
75
76
77
|
# File 'lib/bindata/dsl.rb', line 75
def parser_type
@parser_type
end
|
Instance Method Details
#dsl_params ⇒ Object
132
133
134
135
|
# File 'lib/bindata/dsl.rb', line 132
def dsl_params
abilities = parser_abilities[@parser_type]
send(abilities.at(0), abilities.at(1))
end
|
#endian(endian = nil) ⇒ Object
78
79
80
81
82
83
84
85
|
# File 'lib/bindata/dsl.rb', line 78
def endian(endian = nil)
if endian
set_endian(endian)
elsif @endian.nil?
set_endian(parent_attribute(:endian))
end
@endian
end
|
#fields ⇒ Object
128
129
130
|
# File 'lib/bindata/dsl.rb', line 128
def fields
@fields ||= SanitizedFields.new(namespace, hints, parent_fields)
end
|
#hide(*args) ⇒ Object
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/bindata/dsl.rb', line 117
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_namespace(*args) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/bindata/dsl.rb', line 87
def search_namespace(*args)
@search_namespace ||= parent_attribute(:search_namespace, []).dup
namespace = args.collect(&:to_sym).compact
unless namespace.empty?
if fields?
dsl_raise SyntaxError, "search_namespace must be called before defining fields"
end
@search_namespace = namespace.concat(@search_namespace)
end
@search_namespace
end
|
#search_prefix(*args) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/bindata/dsl.rb', line 102
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
|