lib/bindata/single.rb in bindata-0.6.0 vs lib/bindata/single.rb in bindata-0.7.0
- old
+ new
@@ -18,13 +18,15 @@
# using this param. In the interval between
# calls to #do_read and #done_read, #value
# will return the value of the data read from the
# IO, not the result of the <tt>:value</tt> param.
# [<tt>:check_value</tt>] Raise an error unless the value read in meets
- # this criteria. A boolean return indicates
- # success or failure. Any other return is compared
- # to the value just read in.
+ # this criteria. The variable +value+ is made
+ # available to any lambda assigned to this
+ # parameter. A boolean return indicates success
+ # or failure. Any other return is compared to
+ # the value just read in.
class Single < Base
# These are the parameters used by this class.
optional_parameters :initial_value, :value, :check_value
# Register the names of all subclasses of this class.
@@ -54,14 +56,15 @@
@in_read = true
@value = read_val(io)
# does the value meet expectations?
if has_param?(:check_value)
- expected = eval_param(:check_value)
+ current_value = self.value
+ expected = eval_param(:check_value, :value => current_value)
if not expected
raise ValidityError, "value not as expected"
- elsif @value != expected and expected != true
- raise ValidityError, "value is '#{@value}' but " +
+ elsif current_value != expected and expected != true
+ raise ValidityError, "value is '#{current_value}' but " +
"expected '#{expected}'"
end
end
end