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



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

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

#assert!Object



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

def assert!
  assert_value(snapshot)
end

#assert_value(current_value) ⇒ Object



211
212
213
214
215
216
217
218
# File 'lib/bindata/base_primitive.rb', line 211

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



193
194
195
196
# File 'lib/bindata/base_primitive.rb', line 193

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

#do_read(io) ⇒ Object

:nodoc:



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

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