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
222 223 224 |
# File 'lib/bindata/base_primitive.rb', line 222 def _value reading? ? @value : eval_parameter(:asserted_value) end |
#assert! ⇒ Object
231 232 233 |
# File 'lib/bindata/base_primitive.rb', line 231 def assert! assert_value(snapshot) end |
#assert_value(current_value) ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/bindata/base_primitive.rb', line 235 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
217 218 219 220 |
# File 'lib/bindata/base_primitive.rb', line 217 def assign(val) assert_value(val) super(val) end |
#do_read(io) ⇒ Object
:nodoc:
226 227 228 229 |
# File 'lib/bindata/base_primitive.rb', line 226 def do_read(io) #:nodoc: super(io) assert! end |