Class: BinData::Sanitizer
- Inherits:
-
Object
- Object
- BinData::Sanitizer
- Defined in:
- lib/bindata/sanitize.rb
Overview
The Sanitizer sanitizes the parameters that are passed when creating a BinData object. Sanitizing consists of checking for mandatory, optional and default parameters and ensuring the values of known parameters are valid.
Class Method Summary collapse
-
.sanitize(params, the_class) ⇒ Object
Sanitize
params
forthe_class
.
Instance Method Summary collapse
- #create_sanitized_choices(choices) ⇒ Object
- #create_sanitized_endian(endian) ⇒ Object
- #create_sanitized_fields(endian = nil) ⇒ Object
- #create_sanitized_object_prototype(obj_type, obj_params, endian = nil) ⇒ Object
- #create_sanitized_params(params, the_class) ⇒ Object
-
#initialize ⇒ Sanitizer
constructor
A new instance of Sanitizer.
- #lookup_class(type) ⇒ Object
- #with_endian(endian, &block) ⇒ Object
Constructor Details
#initialize ⇒ Sanitizer
Returns a new instance of Sanitizer.
131 132 133 |
# File 'lib/bindata/sanitize.rb', line 131 def initialize @endian = nil end |
Class Method Details
.sanitize(params, the_class) ⇒ Object
Sanitize params
for the_class
. Returns sanitized parameters.
121 122 123 124 125 126 127 128 |
# File 'lib/bindata/sanitize.rb', line 121 def sanitize(params, the_class) if params.is_a?(SanitizedParameters) and params.all_sanitized? params else sanitizer = self.new sanitizer.create_sanitized_params(params, the_class) end end |
Instance Method Details
#create_sanitized_choices(choices) ⇒ Object
146 147 148 |
# File 'lib/bindata/sanitize.rb', line 146 def create_sanitized_choices(choices) SanitizedChoices.new(self, choices) end |
#create_sanitized_endian(endian) ⇒ Object
142 143 144 |
# File 'lib/bindata/sanitize.rb', line 142 def create_sanitized_endian(endian) SanitizedEndian.new(endian) end |
#create_sanitized_fields(endian = nil) ⇒ Object
150 151 152 |
# File 'lib/bindata/sanitize.rb', line 150 def create_sanitized_fields(endian = nil) SanitizedFields.new(self, endian) end |
#create_sanitized_object_prototype(obj_type, obj_params, endian = nil) ⇒ Object
154 155 156 |
# File 'lib/bindata/sanitize.rb', line 154 def create_sanitized_object_prototype(obj_type, obj_params, endian = nil) SanitizedPrototype.new(self, obj_type, obj_params, endian) end |
#create_sanitized_params(params, the_class) ⇒ Object
135 136 137 138 139 140 |
# File 'lib/bindata/sanitize.rb', line 135 def create_sanitized_params(params, the_class) sanitized_params = as_sanitized_params(params, the_class) sanitized_params.sanitize!(self) sanitized_params end |
#lookup_class(type) ⇒ Object
169 170 171 172 173 174 175 |
# File 'lib/bindata/sanitize.rb', line 169 def lookup_class(type) registered_class = RegisteredClasses.lookup(type, @endian) if registered_class.nil? raise TypeError, "unknown type '#{type}'" end registered_class end |
#with_endian(endian, &block) ⇒ Object
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/bindata/sanitize.rb', line 158 def with_endian(endian, &block) if endian != nil saved_endian = @endian @endian = endian.is_a?(SanitizedEndian) ? endian.endian : endian yield @endian = saved_endian else yield end end |