Module: BinData::BasePrimitive::CheckValuePlugin

Defined in:
lib/bindata/base_primitive.rb

Overview

Logic for the :check_value parameter

Instance Method Summary collapse

Instance Method Details

#check_value(current_value) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
# File 'lib/bindata/base_primitive.rb', line 176

def check_value(current_value)
  expected = eval_parameter(:check_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

#do_read(io) ⇒ Object

:nodoc:



171
172
173
174
# File 'lib/bindata/base_primitive.rb', line 171

def do_read(io) #:nodoc:
  super(io)
  check_value(snapshot)
end