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

- old
+ new

@@ -54,32 +54,33 @@ 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 hide(*args) @hide ||= [] @hide.concat(args.collect { |name| name.to_s }) @hide 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: params[:fields] = fields params[:endian] = endian unless endian.nil? params[:hide] = hide unless hide.empty? super(params, sanitizer) @@ -98,24 +99,24 @@ 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 if self::RESERVED.include?(name) raise NameError.new("", name), - "field '#{name}' is a reserved name", caller(3) + "field '#{name}' is a reserved name in #{self}", caller(3) end end end end end