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
229 230 231 |
# File 'lib/bindata/base_primitive.rb', line 229 def _value reading? ? @value : eval_parameter(:asserted_value) end |
#assert! ⇒ Object
238 239 240 |
# File 'lib/bindata/base_primitive.rb', line 238 def assert! assert_value(snapshot) end |
#assert_value(current_value) ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/bindata/base_primitive.rb', line 242 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
224 225 226 227 |
# File 'lib/bindata/base_primitive.rb', line 224 def assign(val) assert_value(val) super(val) end |
#do_read(io) ⇒ Object
:nodoc:
233 234 235 236 |
# File 'lib/bindata/base_primitive.rb', line 233 def do_read(io) #:nodoc: super(io) assert! end |