Module: BinData::BasePrimitive::AssertedValuePlugin

Defined in:
lib/bindata/base_primitive.rb

Overview

Logic for the :asserted_value parameter

Instance Method Summary collapse

Instance Method Details

#_valueObject



204
205
206
# File 'lib/bindata/base_primitive.rb', line 204

def _value
  reading? ? @value : eval_parameter(:asserted_value)
end

#assert!Object



213
214
215
# File 'lib/bindata/base_primitive.rb', line 213

def assert!
  assert_value(snapshot)
end

#assert_value(current_value) ⇒ Object



217
218
219
220
221
222
223
224
# File 'lib/bindata/base_primitive.rb', line 217

def assert_value(current_value)
  expected = eval_parameter(:asserted_value, value: current_value)
  if current_value != expected
    raise ValidityError,
          "value is '#{current_value}' but " \
          "expected '#{expected}' for #{debug_name}"
  end
end

#assign(val) ⇒ Object



199
200
201
202
# File 'lib/bindata/base_primitive.rb', line 199

def assign(val)
  assert_value(val)
  super(val)
end

#do_read(io) ⇒ Object

:nodoc:



208
209
210
211
# File 'lib/bindata/base_primitive.rb', line 208

def do_read(io) #:nodoc:
  super(io)
  assert!
end