autoparse 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +10 -0
- data/lib/autoparse.rb +88 -78
- data/lib/autoparse/instance.rb +20 -57
- data/lib/autoparse/version.rb +1 -1
- data/spec/autoparse/instance_spec.rb +26 -14
- metadata +7 -15
    
        data/CHANGELOG
    CHANGED
    
    | @@ -1,3 +1,13 @@ | |
| 1 | 
            +
            == 0.2.3
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            * fixed stupid bug in inspect method
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            == 0.2.2
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            * the AutoParse.generate method was changed to use an options Hash
         | 
| 8 | 
            +
            * fixed some issues around array imports and exports
         | 
| 9 | 
            +
            * schemas of type object should now correctly inherit their id URI values
         | 
| 10 | 
            +
             | 
| 1 11 | 
             
            == 0.2.1
         | 
| 2 12 |  | 
| 3 13 | 
             
            * fixed URI resolution when base URI is missing
         | 
    
        data/lib/autoparse.rb
    CHANGED
    
    | @@ -21,7 +21,9 @@ module AutoParse | |
| 21 21 | 
             
                @schemas ||= {}
         | 
| 22 22 | 
             
              end
         | 
| 23 23 |  | 
| 24 | 
            -
              def self.generate(schema_data,  | 
| 24 | 
            +
              def self.generate(schema_data, options={})
         | 
| 25 | 
            +
                uri = options[:uri]
         | 
| 26 | 
            +
                parent = options[:parent]
         | 
| 25 27 | 
             
                if schema_data["extends"]
         | 
| 26 28 | 
             
                  super_uri = uri + Addressable::URI.parse(schema_data["extends"])
         | 
| 27 29 | 
             
                  super_schema = self.schemas[super_uri]
         | 
| @@ -37,6 +39,9 @@ module AutoParse | |
| 37 39 | 
             
                  @uri = Addressable::URI.parse(uri)
         | 
| 38 40 | 
             
                  @uri.normalize! if @uri != nil
         | 
| 39 41 | 
             
                  @schema_data = schema_data
         | 
| 42 | 
            +
                  if !self.uri && parent
         | 
| 43 | 
            +
                    @uri = parent.uri
         | 
| 44 | 
            +
                  end
         | 
| 40 45 |  | 
| 41 46 | 
             
                  def self.additional_properties_schema
         | 
| 42 47 | 
             
                    # Override the superclass implementation so we're not always returning
         | 
| @@ -57,12 +62,9 @@ module AutoParse | |
| 57 62 | 
             
                      property_schema = property_super_schema.data.merge(property_schema)
         | 
| 58 63 | 
             
                    end
         | 
| 59 64 |  | 
| 60 | 
            -
                     | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
                      # If the schema has no ID, it inherits the ID from the parent schema.
         | 
| 64 | 
            -
                      property_schema_class = AutoParse.generate(property_schema, @uri)
         | 
| 65 | 
            -
                    end
         | 
| 65 | 
            +
                    # If the schema has no ID, it inherits the ID from the parent schema.
         | 
| 66 | 
            +
                    property_schema_class =
         | 
| 67 | 
            +
                      AutoParse.generate(property_schema, :parent => self)
         | 
| 66 68 |  | 
| 67 69 | 
             
                    self.properties[property_key] = property_schema_class
         | 
| 68 70 | 
             
                    self.keys[property_name] = property_key
         | 
| @@ -101,7 +103,7 @@ module AutoParse | |
| 101 103 | 
             
                        value = self[stripped_method]
         | 
| 102 104 | 
             
                      else
         | 
| 103 105 | 
             
                        # Method not found.
         | 
| 104 | 
            -
                        super
         | 
| 106 | 
            +
                        super(method, *params, &block)
         | 
| 105 107 | 
             
                      end
         | 
| 106 108 | 
             
                      # If additionalProperties is simply set to true, no parsing takes
         | 
| 107 109 | 
             
                      # place and all values are treated as 'any'.
         | 
| @@ -115,7 +117,9 @@ module AutoParse | |
| 115 117 |  | 
| 116 118 | 
             
                  elsif schema_data['additionalProperties']
         | 
| 117 119 | 
             
                    # Unknown properties follow the supplied schema.
         | 
| 118 | 
            -
                    ap_schema = AutoParse.generate( | 
| 120 | 
            +
                    ap_schema = AutoParse.generate(
         | 
| 121 | 
            +
                      schema_data['additionalProperties'], :parent => self
         | 
| 122 | 
            +
                    )
         | 
| 119 123 | 
             
                    @additional_properties_schema = ap_schema
         | 
| 120 124 | 
             
                    define_method('method_missing') do |method, *params, &block|
         | 
| 121 125 | 
             
                      # We need to convert from Ruby calling style to JavaScript calling
         | 
| @@ -172,6 +176,54 @@ module AutoParse | |
| 172 176 | 
             
                return schema
         | 
| 173 177 | 
             
              end
         | 
| 174 178 |  | 
| 179 | 
            +
              def self.import(value, schema_class, type=nil)
         | 
| 180 | 
            +
                type = schema_class.data['type'] if type == nil
         | 
| 181 | 
            +
                case type
         | 
| 182 | 
            +
                when 'string'
         | 
| 183 | 
            +
                  return AutoParse.import_string(value, schema_class)
         | 
| 184 | 
            +
                when 'boolean'
         | 
| 185 | 
            +
                  return AutoParse.import_boolean(value, schema_class)
         | 
| 186 | 
            +
                when 'integer'
         | 
| 187 | 
            +
                  return AutoParse.import_integer(value, schema_class)
         | 
| 188 | 
            +
                when 'number'
         | 
| 189 | 
            +
                  return AutoParse.import_number(value, schema_class)
         | 
| 190 | 
            +
                when 'array'
         | 
| 191 | 
            +
                  return AutoParse.import_array(value, schema_class)
         | 
| 192 | 
            +
                when 'object'
         | 
| 193 | 
            +
                  return AutoParse.import_object(value, schema_class)
         | 
| 194 | 
            +
                when 'null'
         | 
| 195 | 
            +
                  return nil
         | 
| 196 | 
            +
                when Array
         | 
| 197 | 
            +
                  return AutoParse.import_union(value, schema_class)
         | 
| 198 | 
            +
                else
         | 
| 199 | 
            +
                  return AutoParse.import_any(value, schema_class)
         | 
| 200 | 
            +
                end
         | 
| 201 | 
            +
              end
         | 
| 202 | 
            +
             | 
| 203 | 
            +
              def self.export(value, schema_class, type=nil)
         | 
| 204 | 
            +
                type = schema_class.data['type'] if type == nil
         | 
| 205 | 
            +
                case type
         | 
| 206 | 
            +
                when 'string'
         | 
| 207 | 
            +
                  AutoParse.export_string(value, schema_class)
         | 
| 208 | 
            +
                when 'boolean'
         | 
| 209 | 
            +
                  AutoParse.export_boolean(value, schema_class)
         | 
| 210 | 
            +
                when 'integer'
         | 
| 211 | 
            +
                  AutoParse.export_integer(value, schema_class)
         | 
| 212 | 
            +
                when 'number'
         | 
| 213 | 
            +
                  AutoParse.export_number(value, schema_class)
         | 
| 214 | 
            +
                when 'array'
         | 
| 215 | 
            +
                  AutoParse.export_array(value, schema_class)
         | 
| 216 | 
            +
                when 'object'
         | 
| 217 | 
            +
                  AutoParse.export_object(value, schema_class)
         | 
| 218 | 
            +
                when 'null'
         | 
| 219 | 
            +
                  nil
         | 
| 220 | 
            +
                when Array
         | 
| 221 | 
            +
                  AutoParse.export_union(value, schema_class)
         | 
| 222 | 
            +
                else
         | 
| 223 | 
            +
                  AutoParse.export_any(value, schema_class)
         | 
| 224 | 
            +
                end
         | 
| 225 | 
            +
              end
         | 
| 226 | 
            +
             | 
| 175 227 | 
             
              def self.import_string(value, schema_class)
         | 
| 176 228 | 
             
                if value != nil
         | 
| 177 229 | 
             
                  format = schema_class.data['format']
         | 
| @@ -278,39 +330,39 @@ module AutoParse | |
| 278 330 | 
             
              end
         | 
| 279 331 |  | 
| 280 332 | 
             
              def self.import_array(value, schema_class)
         | 
| 281 | 
            -
                 | 
| 333 | 
            +
                value = (if value != nil && !value.respond_to?(:to_ary)
         | 
| 282 334 | 
             
                  raise TypeError,
         | 
| 283 335 | 
             
                    "Expected Array, got #{value.class}."
         | 
| 284 336 | 
             
                else
         | 
| 285 | 
            -
                  value.to_ary
         | 
| 337 | 
            +
                  (value || []).to_ary.dup
         | 
| 286 338 | 
             
                end)
         | 
| 287 339 | 
             
                items_data = schema_class.data['items']
         | 
| 288 | 
            -
                 | 
| 289 | 
            -
             | 
| 290 | 
            -
             | 
| 291 | 
            -
             | 
| 292 | 
            -
                  else
         | 
| 293 | 
            -
                    items_uri = Addressable::URI.parse(items_data['$ref'])
         | 
| 294 | 
            -
                  end
         | 
| 295 | 
            -
                  items_schema = AutoParse.schemas[items_uri]
         | 
| 296 | 
            -
                  if items_schema
         | 
| 297 | 
            -
                    array.map! do |item|
         | 
| 298 | 
            -
                      items_schema.new(item)
         | 
| 299 | 
            -
                    end
         | 
| 300 | 
            -
                  else
         | 
| 301 | 
            -
                    raise ArgumentError,
         | 
| 302 | 
            -
                      "Could not find schema: #{items_uri}."
         | 
| 303 | 
            -
                  end
         | 
| 340 | 
            +
                items_schema = AutoParse.generate(items_data, :parent => schema_class)
         | 
| 341 | 
            +
                if items_schema.data['$ref']
         | 
| 342 | 
            +
                  # Dereference the schema if necessary.
         | 
| 343 | 
            +
                  items_schema = items_schema.dereference
         | 
| 304 344 | 
             
                end
         | 
| 305 | 
            -
                 | 
| 345 | 
            +
                value.map! do |item|
         | 
| 346 | 
            +
                  AutoParse.import(item, items_schema)
         | 
| 347 | 
            +
                end
         | 
| 348 | 
            +
                value
         | 
| 306 349 | 
             
              end
         | 
| 307 350 |  | 
| 308 351 | 
             
              def self.export_array(value, schema_class)
         | 
| 309 | 
            -
                # FIXME: Each item in the Array needs to be exported as well.
         | 
| 310 352 | 
             
                if value == nil
         | 
| 311 353 | 
             
                  value
         | 
| 312 354 | 
             
                elsif value.respond_to?(:to_ary)
         | 
| 313 | 
            -
                  value.to_ary
         | 
| 355 | 
            +
                  value = value.to_ary.dup
         | 
| 356 | 
            +
                  items_data = schema_class.data['items']
         | 
| 357 | 
            +
                  items_schema = AutoParse.generate(items_data, :parent => schema_class)
         | 
| 358 | 
            +
                  if items_schema.data['$ref']
         | 
| 359 | 
            +
                    # Dereference the schema if necessary.
         | 
| 360 | 
            +
                    items_schema = items_schema.dereference
         | 
| 361 | 
            +
                  end
         | 
| 362 | 
            +
                  value.map! do |item|
         | 
| 363 | 
            +
                    AutoParse.export(item, items_schema)
         | 
| 364 | 
            +
                  end
         | 
| 365 | 
            +
                  value
         | 
| 314 366 | 
             
                else
         | 
| 315 367 | 
             
                  raise TypeError, "Expected Array, got #{value.class}."
         | 
| 316 368 | 
             
                end
         | 
| @@ -335,54 +387,16 @@ module AutoParse | |
| 335 387 |  | 
| 336 388 | 
             
              def self.import_union(value, schema_class)
         | 
| 337 389 | 
             
                import_type = match_type(
         | 
| 338 | 
            -
                  value, schema_class.data['type'], schema_class | 
| 390 | 
            +
                  value, schema_class.data['type'], schema_class
         | 
| 339 391 | 
             
                )
         | 
| 340 | 
            -
                 | 
| 341 | 
            -
                when 'string'
         | 
| 342 | 
            -
                  AutoParse.import_string(value, schema_class)
         | 
| 343 | 
            -
                when 'boolean'
         | 
| 344 | 
            -
                  AutoParse.import_boolean(value, schema_class)
         | 
| 345 | 
            -
                when 'integer'
         | 
| 346 | 
            -
                  AutoParse.import_integer(value, schema_class)
         | 
| 347 | 
            -
                when 'number'
         | 
| 348 | 
            -
                  AutoParse.import_number(value, schema_class)
         | 
| 349 | 
            -
                when 'array'
         | 
| 350 | 
            -
                  AutoParse.import_array(value, schema_class)
         | 
| 351 | 
            -
                when 'object'
         | 
| 352 | 
            -
                  AutoParse.import_object(value, schema_class)
         | 
| 353 | 
            -
                when 'null'
         | 
| 354 | 
            -
                  nil
         | 
| 355 | 
            -
                when Class
         | 
| 356 | 
            -
                  AutoParse.import_object(value, import_type)
         | 
| 357 | 
            -
                else
         | 
| 358 | 
            -
                  AutoParse.import_any(value, schema_class)
         | 
| 359 | 
            -
                end
         | 
| 392 | 
            +
                AutoParse.import(value, schema_class, import_type)
         | 
| 360 393 | 
             
              end
         | 
| 361 394 |  | 
| 362 395 | 
             
              def self.export_union(value, schema_class)
         | 
| 363 396 | 
             
                export_type = match_type(
         | 
| 364 | 
            -
                  value, schema_class.data['type'], schema_class | 
| 397 | 
            +
                  value, schema_class.data['type'], schema_class
         | 
| 365 398 | 
             
                )
         | 
| 366 | 
            -
                 | 
| 367 | 
            -
                when 'string'
         | 
| 368 | 
            -
                  AutoParse.export_string(value, schema_class)
         | 
| 369 | 
            -
                when 'boolean'
         | 
| 370 | 
            -
                  AutoParse.export_boolean(value, schema_class)
         | 
| 371 | 
            -
                when 'integer'
         | 
| 372 | 
            -
                  AutoParse.export_integer(value, schema_class)
         | 
| 373 | 
            -
                when 'number'
         | 
| 374 | 
            -
                  AutoParse.export_number(value, schema_class)
         | 
| 375 | 
            -
                when 'array'
         | 
| 376 | 
            -
                  AutoParse.export_array(value, schema_class)
         | 
| 377 | 
            -
                when 'object'
         | 
| 378 | 
            -
                  AutoParse.export_object(value, schema_class)
         | 
| 379 | 
            -
                when 'null'
         | 
| 380 | 
            -
                  nil
         | 
| 381 | 
            -
                when Class
         | 
| 382 | 
            -
                  AutoParse.export_object(value, export_type)
         | 
| 383 | 
            -
                else
         | 
| 384 | 
            -
                  AutoParse.export_any(value, schema_class)
         | 
| 385 | 
            -
                end
         | 
| 399 | 
            +
                AutoParse.export(value, schema_class, export_type)
         | 
| 386 400 | 
             
              end
         | 
| 387 401 |  | 
| 388 402 | 
             
              def self.import_any(value, schema_class)
         | 
| @@ -397,7 +411,7 @@ module AutoParse | |
| 397 411 | 
             
              # Given a value and a union of types, selects the type which is the best
         | 
| 398 412 | 
             
              # match for the given value. More than one type may match the value, in which
         | 
| 399 413 | 
             
              # case, the first type in the union will be returned.
         | 
| 400 | 
            -
              def self.match_type(value, union,  | 
| 414 | 
            +
              def self.match_type(value, union, parent=nil)
         | 
| 401 415 | 
             
                possible_types = [union].flatten.compact
         | 
| 402 416 | 
             
                # Strict pass
         | 
| 403 417 | 
             
                for type in possible_types
         | 
| @@ -419,11 +433,7 @@ module AutoParse | |
| 419 433 | 
             
                    return 'null' if value.nil?
         | 
| 420 434 | 
             
                  when Hash
         | 
| 421 435 | 
             
                    # Schema embedded directly.
         | 
| 422 | 
            -
                     | 
| 423 | 
            -
                      schema_class = AutoParse.generate(type)
         | 
| 424 | 
            -
                    else
         | 
| 425 | 
            -
                      schema_class = AutoParse.generate(type, base_uri)
         | 
| 426 | 
            -
                    end
         | 
| 436 | 
            +
                    schema_class = AutoParse.generate(type, :parent => parent)
         | 
| 427 437 | 
             
                    if type['$ref']
         | 
| 428 438 | 
             
                      schema_class = schema_class.dereference
         | 
| 429 439 | 
             
                    end
         | 
    
        data/lib/autoparse/instance.rb
    CHANGED
    
    | @@ -29,9 +29,20 @@ module AutoParse | |
| 29 29 | 
             
                def self.dereference
         | 
| 30 30 | 
             
                  if @schema_data['$ref']
         | 
| 31 31 | 
             
                    # Dereference the schema if necessary.
         | 
| 32 | 
            -
                     | 
| 33 | 
            -
             | 
| 32 | 
            +
                    ref_uri = Addressable::URI.parse(@schema_data['$ref'])
         | 
| 33 | 
            +
                    if self.uri
         | 
| 34 | 
            +
                      schema_uri =
         | 
| 35 | 
            +
                        self.uri + Addressable::URI.parse(@schema_data['$ref'])
         | 
| 36 | 
            +
                    else
         | 
| 37 | 
            +
                      if ref_uri.relative?
         | 
| 38 | 
            +
                        warn("Schema URI is relative, could not resolve against parent.")
         | 
| 39 | 
            +
                      else
         | 
| 40 | 
            +
                        warn("Could not resolve URI against parent.")
         | 
| 41 | 
            +
                      end
         | 
| 42 | 
            +
                      schema_uri = ref_uri
         | 
| 43 | 
            +
                    end
         | 
| 34 44 | 
             
                    schema_class = AutoParse.schemas[schema_uri]
         | 
| 45 | 
            +
                    warn("Schema URI mismatch.") if schema_class.uri != schema_uri
         | 
| 35 46 | 
             
                    if schema_class == nil
         | 
| 36 47 | 
             
                      raise ArgumentError,
         | 
| 37 48 | 
             
                        "Could not find schema: #{@schema_data['$ref']}. " +
         | 
| @@ -137,13 +148,7 @@ module AutoParse | |
| 137 148 | 
             
                  else
         | 
| 138 149 | 
             
                    # This is highly ineffecient, but currently hard to avoid given the
         | 
| 139 150 | 
             
                    # schema is anonymous, making lookups very difficult.
         | 
| 140 | 
            -
                     | 
| 141 | 
            -
                      schema = AutoParse.generate(schema_data)
         | 
| 142 | 
            -
                    else
         | 
| 143 | 
            -
                      # If the schema has no ID, it inherits the ID from the parent schema,
         | 
| 144 | 
            -
                      # which should be `self`.
         | 
| 145 | 
            -
                      schema = AutoParse.generate(schema_data, self.uri)
         | 
| 146 | 
            -
                    end
         | 
| 151 | 
            +
                    schema = AutoParse.generate(schema_data, :parent => self)
         | 
| 147 152 | 
             
                    begin
         | 
| 148 153 | 
             
                      return schema.new(property_value).valid?
         | 
| 149 154 | 
             
                    rescue TypeError, ArgumentError, ::JSON::ParserError
         | 
| @@ -334,26 +339,7 @@ module AutoParse | |
| 334 339 |  | 
| 335 340 | 
             
                  value = self[property_key] || schema_class.data['default']
         | 
| 336 341 |  | 
| 337 | 
            -
                   | 
| 338 | 
            -
                  when 'string'
         | 
| 339 | 
            -
                    AutoParse.import_string(value, schema_class)
         | 
| 340 | 
            -
                  when 'boolean'
         | 
| 341 | 
            -
                    AutoParse.import_boolean(value, schema_class)
         | 
| 342 | 
            -
                  when 'integer'
         | 
| 343 | 
            -
                    AutoParse.import_integer(value, schema_class)
         | 
| 344 | 
            -
                  when 'number'
         | 
| 345 | 
            -
                    AutoParse.import_number(value, schema_class)
         | 
| 346 | 
            -
                  when 'array'
         | 
| 347 | 
            -
                    AutoParse.import_array(value, schema_class)
         | 
| 348 | 
            -
                  when 'object'
         | 
| 349 | 
            -
                    AutoParse.import_object(value, schema_class)
         | 
| 350 | 
            -
                  when 'null'
         | 
| 351 | 
            -
                    nil
         | 
| 352 | 
            -
                  when Array
         | 
| 353 | 
            -
                    AutoParse.import_union(value, schema_class)
         | 
| 354 | 
            -
                  else
         | 
| 355 | 
            -
                    AutoParse.import_any(value, schema_class)
         | 
| 356 | 
            -
                  end
         | 
| 342 | 
            +
                  AutoParse.import(value, schema_class)
         | 
| 357 343 | 
             
                end
         | 
| 358 344 | 
             
                protected :__get__
         | 
| 359 345 |  | 
| @@ -368,26 +354,7 @@ module AutoParse | |
| 368 354 | 
             
                    self.class.properties[property_key] = schema_class
         | 
| 369 355 | 
             
                  end
         | 
| 370 356 |  | 
| 371 | 
            -
                   | 
| 372 | 
            -
                  when 'string'
         | 
| 373 | 
            -
                    self[property_key] = AutoParse.export_string(value, schema_class)
         | 
| 374 | 
            -
                  when 'boolean'
         | 
| 375 | 
            -
                    self[property_key] = AutoParse.export_boolean(value, schema_class)
         | 
| 376 | 
            -
                  when 'integer'
         | 
| 377 | 
            -
                    self[property_key] = AutoParse.export_integer(value, schema_class)
         | 
| 378 | 
            -
                  when 'number'
         | 
| 379 | 
            -
                    self[property_key] = AutoParse.export_number(value, schema_class)
         | 
| 380 | 
            -
                  when 'array'
         | 
| 381 | 
            -
                    self[property_key] = AutoParse.export_array(value, schema_class)
         | 
| 382 | 
            -
                  when 'object'
         | 
| 383 | 
            -
                    self[property_key] = AutoParse.export_object(value, schema_class)
         | 
| 384 | 
            -
                  when 'null'
         | 
| 385 | 
            -
                    self[property_key] = nil
         | 
| 386 | 
            -
                  when Array
         | 
| 387 | 
            -
                    self[property_key] = AutoParse.export_union(value, schema_class)
         | 
| 388 | 
            -
                  else
         | 
| 389 | 
            -
                    self[property_key] = AutoParse.export_any(value, schema_class)
         | 
| 390 | 
            -
                  end
         | 
| 357 | 
            +
                  self[property_key] = AutoParse.export(value, schema_class)
         | 
| 391 358 | 
             
                end
         | 
| 392 359 | 
             
                protected :__set__
         | 
| 393 360 |  | 
| @@ -465,14 +432,10 @@ module AutoParse | |
| 465 432 | 
             
                #
         | 
| 466 433 | 
             
                # @return [String] The instance's state, as a <code>String</code>.
         | 
| 467 434 | 
             
                def inspect
         | 
| 468 | 
            -
                   | 
| 469 | 
            -
                     | 
| 470 | 
            -
             | 
| 471 | 
            -
             | 
| 472 | 
            -
                    )
         | 
| 473 | 
            -
                  else
         | 
| 474 | 
            -
                    sprintf("#<%s:%#0x>", self.class.to_s, self.object_id)
         | 
| 475 | 
            -
                  end
         | 
| 435 | 
            +
                  sprintf(
         | 
| 436 | 
            +
                    "#<%s:%#0x DATA:%s>",
         | 
| 437 | 
            +
                    self.class.to_s, self.object_id, self.to_hash.inspect
         | 
| 438 | 
            +
                  )
         | 
| 476 439 | 
             
                end
         | 
| 477 440 | 
             
              end
         | 
| 478 441 |  | 
    
        data/lib/autoparse/version.rb
    CHANGED
    
    
| @@ -77,7 +77,7 @@ describe AutoParse::Instance, 'with the geo schema' do | |
| 77 77 | 
             
                  :path => File.expand_path(File.join(spec_dir, './data/geo.json'))
         | 
| 78 78 | 
             
                )
         | 
| 79 79 | 
             
                @schema_data = JSON.parse(File.open(@uri.path, 'r') { |f| f.read })
         | 
| 80 | 
            -
                @parser = AutoParse.generate(@schema_data, @uri)
         | 
| 80 | 
            +
                @parser = AutoParse.generate(@schema_data, :uri => @uri)
         | 
| 81 81 | 
             
              end
         | 
| 82 82 |  | 
| 83 83 | 
             
              it 'should have the correct URI' do
         | 
| @@ -156,7 +156,7 @@ describe AutoParse::Instance, 'with the address schema' do | |
| 156 156 | 
             
                  :path => File.expand_path(File.join(spec_dir, './data/address.json'))
         | 
| 157 157 | 
             
                )
         | 
| 158 158 | 
             
                @schema_data = JSON.parse(File.open(@uri.path, 'r') { |f| f.read })
         | 
| 159 | 
            -
                @parser = AutoParse.generate(@schema_data, @uri)
         | 
| 159 | 
            +
                @parser = AutoParse.generate(@schema_data, :uri => @uri)
         | 
| 160 160 | 
             
              end
         | 
| 161 161 |  | 
| 162 162 | 
             
              it 'should have the correct URI' do
         | 
| @@ -271,7 +271,7 @@ describe AutoParse::Instance, 'with the person schema' do | |
| 271 271 | 
             
                  :path => File.expand_path(File.join(spec_dir, './data/person.json'))
         | 
| 272 272 | 
             
                )
         | 
| 273 273 | 
             
                @schema_data = JSON.parse(File.open(@uri.path, 'r') { |f| f.read })
         | 
| 274 | 
            -
                @parser = AutoParse.generate(@schema_data, @uri)
         | 
| 274 | 
            +
                @parser = AutoParse.generate(@schema_data, :uri => @uri)
         | 
| 275 275 | 
             
              end
         | 
| 276 276 |  | 
| 277 277 | 
             
              it 'should have the correct URI' do
         | 
| @@ -375,7 +375,9 @@ describe AutoParse::Instance, 'with the adult schema' do | |
| 375 375 | 
             
                )
         | 
| 376 376 | 
             
                @person_schema_data =
         | 
| 377 377 | 
             
                  JSON.parse(File.open(@person_uri.path, 'r') { |f| f.read })
         | 
| 378 | 
            -
                @person_parser = AutoParse.generate( | 
| 378 | 
            +
                @person_parser = AutoParse.generate(
         | 
| 379 | 
            +
                  @person_schema_data, :uri => @person_uri
         | 
| 380 | 
            +
                )
         | 
| 379 381 |  | 
| 380 382 | 
             
                @adult_uri = Addressable::URI.new(
         | 
| 381 383 | 
             
                  :scheme => 'file',
         | 
| @@ -384,7 +386,7 @@ describe AutoParse::Instance, 'with the adult schema' do | |
| 384 386 | 
             
                )
         | 
| 385 387 | 
             
                @adult_schema_data =
         | 
| 386 388 | 
             
                  JSON.parse(File.open(@adult_uri.path, 'r') { |f| f.read })
         | 
| 387 | 
            -
                @adult_parser = AutoParse.generate(@adult_schema_data, @adult_uri)
         | 
| 389 | 
            +
                @adult_parser = AutoParse.generate(@adult_schema_data, :uri => @adult_uri)
         | 
| 388 390 | 
             
              end
         | 
| 389 391 |  | 
| 390 392 | 
             
              it 'should have the correct URI' do
         | 
| @@ -489,7 +491,9 @@ describe AutoParse::Instance, 'with the positive schema' do | |
| 489 491 | 
             
                )
         | 
| 490 492 | 
             
                @positive_schema_data =
         | 
| 491 493 | 
             
                  JSON.parse(File.open(@positive_uri.path, 'r') { |f| f.read })
         | 
| 492 | 
            -
                @positive_parser = AutoParse.generate( | 
| 494 | 
            +
                @positive_parser = AutoParse.generate(
         | 
| 495 | 
            +
                  @positive_schema_data, :uri => @positive_uri
         | 
| 496 | 
            +
                )
         | 
| 493 497 | 
             
              end
         | 
| 494 498 |  | 
| 495 499 | 
             
              it 'should have the correct URI' do
         | 
| @@ -518,7 +522,9 @@ describe AutoParse::Instance, 'with the account schema' do | |
| 518 522 | 
             
                )
         | 
| 519 523 | 
             
                @positive_schema_data =
         | 
| 520 524 | 
             
                  JSON.parse(File.open(@positive_uri.path, 'r') { |f| f.read })
         | 
| 521 | 
            -
                @positive_parser = AutoParse.generate( | 
| 525 | 
            +
                @positive_parser = AutoParse.generate(
         | 
| 526 | 
            +
                  @positive_schema_data, :uri => @positive_uri
         | 
| 527 | 
            +
                )
         | 
| 522 528 |  | 
| 523 529 | 
             
                @account_uri = Addressable::URI.new(
         | 
| 524 530 | 
             
                  :scheme => 'file',
         | 
| @@ -527,7 +533,9 @@ describe AutoParse::Instance, 'with the account schema' do | |
| 527 533 | 
             
                )
         | 
| 528 534 | 
             
                @account_schema_data =
         | 
| 529 535 | 
             
                  JSON.parse(File.open(@account_uri.path, 'r') { |f| f.read })
         | 
| 530 | 
            -
                @account_parser = AutoParse.generate( | 
| 536 | 
            +
                @account_parser = AutoParse.generate(
         | 
| 537 | 
            +
                  @account_schema_data, :uri => @account_uri
         | 
| 538 | 
            +
                )
         | 
| 531 539 | 
             
              end
         | 
| 532 540 |  | 
| 533 541 | 
             
              it 'should have the correct URI' do
         | 
| @@ -624,7 +632,9 @@ describe AutoParse::Instance, 'with the card schema' do | |
| 624 632 | 
             
                )
         | 
| 625 633 | 
             
                @address_schema_data =
         | 
| 626 634 | 
             
                  JSON.parse(File.open(@address_uri.path, 'r') { |f| f.read })
         | 
| 627 | 
            -
                @address_parser = AutoParse.generate( | 
| 635 | 
            +
                @address_parser = AutoParse.generate(
         | 
| 636 | 
            +
                  @address_schema_data, :uri => @address_uri
         | 
| 637 | 
            +
                )
         | 
| 628 638 |  | 
| 629 639 | 
             
                @geo_uri = Addressable::URI.new(
         | 
| 630 640 | 
             
                  :scheme => 'file',
         | 
| @@ -633,7 +643,7 @@ describe AutoParse::Instance, 'with the card schema' do | |
| 633 643 | 
             
                )
         | 
| 634 644 | 
             
                @geo_schema_data =
         | 
| 635 645 | 
             
                  JSON.parse(File.open(@geo_uri.path, 'r') { |f| f.read })
         | 
| 636 | 
            -
                @geo_parser = AutoParse.generate(@geo_schema_data, @geo_uri)
         | 
| 646 | 
            +
                @geo_parser = AutoParse.generate(@geo_schema_data, :uri => @geo_uri)
         | 
| 637 647 |  | 
| 638 648 | 
             
                @card_uri = Addressable::URI.new(
         | 
| 639 649 | 
             
                  :scheme => 'file',
         | 
| @@ -642,7 +652,7 @@ describe AutoParse::Instance, 'with the card schema' do | |
| 642 652 | 
             
                )
         | 
| 643 653 | 
             
                @card_schema_data =
         | 
| 644 654 | 
             
                  JSON.parse(File.open(@card_uri.path, 'r') { |f| f.read })
         | 
| 645 | 
            -
                @card_parser = AutoParse.generate(@card_schema_data, @card_uri)
         | 
| 655 | 
            +
                @card_parser = AutoParse.generate(@card_schema_data, :uri => @card_uri)
         | 
| 646 656 | 
             
              end
         | 
| 647 657 |  | 
| 648 658 | 
             
              it 'should have the correct URI' do
         | 
| @@ -940,7 +950,7 @@ describe AutoParse::Instance, 'with the calendar schema' do | |
| 940 950 | 
             
                )
         | 
| 941 951 | 
             
                @geo_schema_data =
         | 
| 942 952 | 
             
                  JSON.parse(File.open(@geo_uri.path, 'r') { |f| f.read })
         | 
| 943 | 
            -
                @geo_parser = AutoParse.generate(@geo_schema_data, @geo_uri)
         | 
| 953 | 
            +
                @geo_parser = AutoParse.generate(@geo_schema_data, :uri => @geo_uri)
         | 
| 944 954 |  | 
| 945 955 | 
             
                @calendar_uri = Addressable::URI.new(
         | 
| 946 956 | 
             
                  :scheme => 'file',
         | 
| @@ -949,7 +959,9 @@ describe AutoParse::Instance, 'with the calendar schema' do | |
| 949 959 | 
             
                )
         | 
| 950 960 | 
             
                @calendar_schema_data =
         | 
| 951 961 | 
             
                  JSON.parse(File.open(@calendar_uri.path, 'r') { |f| f.read })
         | 
| 952 | 
            -
                @calendar_parser = AutoParse.generate( | 
| 962 | 
            +
                @calendar_parser = AutoParse.generate(
         | 
| 963 | 
            +
                  @calendar_schema_data, :uri => @calendar_uri
         | 
| 964 | 
            +
                )
         | 
| 953 965 | 
             
              end
         | 
| 954 966 |  | 
| 955 967 | 
             
              it 'should have the correct URI' do
         | 
| @@ -1118,7 +1130,7 @@ describe AutoParse::Instance, 'with the node schema' do | |
| 1118 1130 | 
             
                  :path => File.expand_path(File.join(spec_dir, './data/node.json'))
         | 
| 1119 1131 | 
             
                )
         | 
| 1120 1132 | 
             
                @schema_data = JSON.parse(File.open(@uri.path, 'r') { |f| f.read })
         | 
| 1121 | 
            -
                @parser = AutoParse.generate(@schema_data, @uri)
         | 
| 1133 | 
            +
                @parser = AutoParse.generate(@schema_data, :uri => @uri)
         | 
| 1122 1134 | 
             
              end
         | 
| 1123 1135 |  | 
| 1124 1136 | 
             
              it 'should have the correct URI' do
         | 
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,12 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: autoparse
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
               | 
| 5 | 
            -
              prerelease: 
         | 
| 4 | 
            +
              prerelease: false
         | 
| 6 5 | 
             
              segments: 
         | 
| 7 6 | 
             
              - 0
         | 
| 8 7 | 
             
              - 2
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 0.2. | 
| 8 | 
            +
              - 3
         | 
| 9 | 
            +
              version: 0.2.3
         | 
| 11 10 | 
             
            platform: ruby
         | 
| 12 11 | 
             
            authors: 
         | 
| 13 12 | 
             
            - Bob Aman
         | 
| @@ -15,7 +14,8 @@ autorequire: | |
| 15 14 | 
             
            bindir: bin
         | 
| 16 15 | 
             
            cert_chain: []
         | 
| 17 16 |  | 
| 18 | 
            -
            date: 2011-10- | 
| 17 | 
            +
            date: 2011-10-21 00:00:00 +03:00
         | 
| 18 | 
            +
            default_executable: 
         | 
| 19 19 | 
             
            dependencies: 
         | 
| 20 20 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 21 21 | 
             
              name: addressable
         | 
| @@ -25,7 +25,6 @@ dependencies: | |
| 25 25 | 
             
                requirements: 
         | 
| 26 26 | 
             
                - - ~>
         | 
| 27 27 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 28 | 
            -
                    hash: 3
         | 
| 29 28 | 
             
                    segments: 
         | 
| 30 29 | 
             
                    - 2
         | 
| 31 30 | 
             
                    - 2
         | 
| @@ -41,7 +40,6 @@ dependencies: | |
| 41 40 | 
             
                requirements: 
         | 
| 42 41 | 
             
                - - ">="
         | 
| 43 42 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 44 | 
            -
                    hash: 11
         | 
| 45 43 | 
             
                    segments: 
         | 
| 46 44 | 
             
                    - 1
         | 
| 47 45 | 
             
                    - 4
         | 
| @@ -57,7 +55,6 @@ dependencies: | |
| 57 55 | 
             
                requirements: 
         | 
| 58 56 | 
             
                - - ">="
         | 
| 59 57 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 60 | 
            -
                    hash: 37
         | 
| 61 58 | 
             
                    segments: 
         | 
| 62 59 | 
             
                    - 0
         | 
| 63 60 | 
             
                    - 9
         | 
| @@ -73,7 +70,6 @@ dependencies: | |
| 73 70 | 
             
                requirements: 
         | 
| 74 71 | 
             
                - - ~>
         | 
| 75 72 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 76 | 
            -
                    hash: 57
         | 
| 77 73 | 
             
                    segments: 
         | 
| 78 74 | 
             
                    - 0
         | 
| 79 75 | 
             
                    - 8
         | 
| @@ -89,7 +85,6 @@ dependencies: | |
| 89 85 | 
             
                requirements: 
         | 
| 90 86 | 
             
                - - ~>
         | 
| 91 87 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 92 | 
            -
                    hash: 23
         | 
| 93 88 | 
             
                    segments: 
         | 
| 94 89 | 
             
                    - 2
         | 
| 95 90 | 
             
                    - 6
         | 
| @@ -105,7 +100,6 @@ dependencies: | |
| 105 100 | 
             
                requirements: 
         | 
| 106 101 | 
             
                - - ~>
         | 
| 107 102 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 108 | 
            -
                    hash: 23
         | 
| 109 103 | 
             
                    segments: 
         | 
| 110 104 | 
             
                    - 0
         | 
| 111 105 | 
             
                    - 3
         | 
| @@ -121,7 +115,6 @@ dependencies: | |
| 121 115 | 
             
                requirements: 
         | 
| 122 116 | 
             
                - - ~>
         | 
| 123 117 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 124 | 
            -
                    hash: 23
         | 
| 125 118 | 
             
                    segments: 
         | 
| 126 119 | 
             
                    - 1
         | 
| 127 120 | 
             
                    - 1
         | 
| @@ -176,6 +169,7 @@ files: | |
| 176 169 | 
             
            - LICENSE
         | 
| 177 170 | 
             
            - Rakefile
         | 
| 178 171 | 
             
            - README.md
         | 
| 172 | 
            +
            has_rdoc: true
         | 
| 179 173 | 
             
            homepage: http://autoparse.rubyforge.org/
         | 
| 180 174 | 
             
            licenses: []
         | 
| 181 175 |  | 
| @@ -190,7 +184,6 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 190 184 | 
             
              requirements: 
         | 
| 191 185 | 
             
              - - ">="
         | 
| 192 186 | 
             
                - !ruby/object:Gem::Version 
         | 
| 193 | 
            -
                  hash: 3
         | 
| 194 187 | 
             
                  segments: 
         | 
| 195 188 | 
             
                  - 0
         | 
| 196 189 | 
             
                  version: "0"
         | 
| @@ -199,14 +192,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 199 192 | 
             
              requirements: 
         | 
| 200 193 | 
             
              - - ">="
         | 
| 201 194 | 
             
                - !ruby/object:Gem::Version 
         | 
| 202 | 
            -
                  hash: 3
         | 
| 203 195 | 
             
                  segments: 
         | 
| 204 196 | 
             
                  - 0
         | 
| 205 197 | 
             
                  version: "0"
         | 
| 206 198 | 
             
            requirements: []
         | 
| 207 199 |  | 
| 208 200 | 
             
            rubyforge_project: autoparse
         | 
| 209 | 
            -
            rubygems_version: 1. | 
| 201 | 
            +
            rubygems_version: 1.3.7
         | 
| 210 202 | 
             
            signing_key: 
         | 
| 211 203 | 
             
            specification_version: 3
         | 
| 212 204 | 
             
            summary: A parsing system based on JSON Schema.
         |