lib/bindata/primitive.rb in bindata-0.11.1 vs lib/bindata/primitive.rb in bindata-1.0.0

- old
+ new

@@ -70,26 +70,27 @@ def endian(endian = nil) @endian ||= nil if [:little, :big].include?(endian) @endian = endian elsif endian != nil - raise ArgumentError, "unknown value for endian '#{endian}'", caller(1) + raise ArgumentError, + "unknown value for endian '#{endian}' in #{self}", caller(1) end @endian end - def method_missing(symbol, *args) + def method_missing(symbol, *args) #:nodoc: name, params = args type = symbol name = name.to_s params ||= {} append_field(type, name, params) end - def sanitize_parameters!(params, sanitizer) + def sanitize_parameters!(params, sanitizer) #:nodoc: struct_params = {} struct_params[:fields] = fields struct_params[:endian] = endian unless endian.nil? params[:struct_params] = struct_params @@ -108,21 +109,21 @@ def append_field(type, name, params) ensure_valid_name(name) fields.add_field(type, name, params) - rescue TypeError - raise TypeError, "unknown type '#{type}' for #{self}", caller(2) + rescue UnknownTypeError => err + raise TypeError, "unknown type '#{err.message}' for #{self}", caller(2) end def ensure_valid_name(name) if fields.field_names.include?(name) raise SyntaxError, "duplicate field '#{name}' in #{self}", caller(3) end - if self.instance_methods.include?(name) + if self.instance_methods.collect { |meth| meth.to_s }.include?(name) raise NameError.new("", name), - "field '#{name}' shadows an existing method", caller(3) + "field '#{name}' shadows an existing method in #{self}", caller(3) end end end mandatory_parameter :struct_params @@ -131,19 +132,19 @@ super(params, parent) @struct = BinData::Struct.new(get_parameter(:struct_params), self) end - def method_missing(symbol, *args, &block) + def method_missing(symbol, *args, &block) #:nodoc: @struct.__send__(symbol, *args, &block) end - def debug_name_of(child) + def debug_name_of(child) #:nodoc: debug_name + "-internal-" end - def offset_of(child) - offset + def offset_of(child) #:nodoc: + @struct.offset_of(child) end #--------------- private