Module: BinData::BasePrimitive::AssertPlugin

Defined in:
lib/bindata/base_primitive.rb

Overview

Logic for the :assert parameter

Instance Method Summary collapse

Instance Method Details

#assert!Object

Raises:



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

def assert!
  current_value = snapshot
  expected = eval_parameter(:assert, value: current_value)

  msg =
    if !expected
      "value '#{current_value}' not as expected"
    elsif expected != true && current_value != expected
      "value is '#{current_value}' but expected '#{expected}'"
    else
      nil
    end

  raise ValidityError, "#{msg} for #{debug_name}" if msg
end

#assign(val) ⇒ Object



165
166
167
168
# File 'lib/bindata/base_primitive.rb', line 165

def assign(val)
  super(val)
  assert!
end

#do_read(io) ⇒ Object

:nodoc:



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

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