Module: BinData::BasePrimitive::AssertedValuePlugin
- Defined in:
- lib/bindata/base_primitive.rb
Overview
Logic for the :asserted_value parameter
Instance Method Summary collapse
- #_value ⇒ Object
- #assert! ⇒ Object
- #assert_value(current_value) ⇒ Object
- #assign(val) ⇒ Object
-
#do_read(io) ⇒ Object
:nodoc:.
Instance Method Details
#_value ⇒ Object
200 201 202 |
# File 'lib/bindata/base_primitive.rb', line 200 def _value reading? ? @value : eval_parameter(:asserted_value) end |
#assert! ⇒ Object
209 210 211 |
# File 'lib/bindata/base_primitive.rb', line 209 def assert! assert_value(snapshot) end |
#assert_value(current_value) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/bindata/base_primitive.rb', line 213 def assert_value(current_value) expected = eval_parameter(:asserted_value, :value => current_value) if not expected raise ValidityError, "value '#{current_value}' not as expected for #{debug_name}" elsif current_value != expected and expected != true raise ValidityError, "value is '#{current_value}' but " + "expected '#{expected}' for #{debug_name}" end end |
#assign(val) ⇒ Object
195 196 197 198 |
# File 'lib/bindata/base_primitive.rb', line 195 def assign(val) assert_value(val) super(val) end |
#do_read(io) ⇒ Object
:nodoc:
204 205 206 207 |
# File 'lib/bindata/base_primitive.rb', line 204 def do_read(io) #:nodoc: super(io) assert! end |