lib/bindata/single.rb in bindata-0.9.1 vs lib/bindata/single.rb in bindata-0.9.2

- old
+ new

@@ -43,20 +43,15 @@ # 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 + class Single < BinData::Base # These are the parameters used by this class. optional_parameters :initial_value, :value, :check_value mutually_exclusive_parameters :initial_value, :value - # Single objects don't contain fields so this returns an empty list. - def self.all_possible_field_names(sanitized_params) - [] - end - def initialize(params = {}, env = nil) super(params, env) clear end @@ -74,20 +69,10 @@ # Single objects are single_values def single_value? true end - # Single objects don't contain fields so this returns an empty list. - def field_names - [] - end - - # Returns a snapshot of this data object. - def snapshot - value - end - # To be called after calling #do_read. def done_read @in_read = false end @@ -120,11 +105,11 @@ # does the value meet expectations? if has_param?(:check_value) current_value = self.value expected = eval_param(:check_value, :value => current_value) if not expected - raise ValidityError, "value not as expected" + raise ValidityError, "value '#{current_value}' not as expected" elsif current_value != expected and expected != true raise ValidityError, "value is '#{current_value}' but " + "expected '#{expected}'" end end @@ -137,9 +122,14 @@ end # Returns the number of bytes it will take to write this data. def _do_num_bytes(ignored) val_to_str(_value).length + end + + # Returns a snapshot of this data object. + def _snapshot + value end # The unmodified value of this data object. Note that #value calls this # method. This is so that #value can be overridden in subclasses to # modify the value.