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:



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/bindata/base_primitive.rb', line 180

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



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

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

#do_read(io) ⇒ Object

:nodoc:



175
176
177
178
# File 'lib/bindata/base_primitive.rb', line 175

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