Skip to content

Commit

Permalink
Make tests pass on Ruby 1.9.
Browse files Browse the repository at this point in the history
* URI#path= no longer accepts a Pathname.
* Array#nitems is deprecated.
  • Loading branch information
jarib committed Jan 9, 2011
1 parent 356564c commit 2150840
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/json-schema/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(schema,uri)
if @schema['id']
temp_uri = URI.parse(@schema['id'])
if temp_uri.relative?
uri.path = (Pathname.new(uri.path).parent + @schema['id']).cleanpath
uri.path = (Pathname.new(uri.path).parent + @schema['id']).cleanpath.to_s
temp_uri = uri
end
@uri = temp_uri
Expand Down
12 changes: 6 additions & 6 deletions lib/json-schema/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def validate_maximum(current_schema, data, fragments)

# Validate the minimum number of items in an array
def validate_minItems(current_schema, data, fragments)
if data.is_a?(Array) && (data.nitems < current_schema.schema['minItems'])
if data.is_a?(Array) && (data.compact.size < current_schema.schema['minItems'])
message = "The property '#{build_fragment(fragments)}' did not contain a minimum number of items #{current_schema.schema['minItems']}"
raise ValidationError.new(message, fragments, current_schema)
end
Expand All @@ -209,7 +209,7 @@ def validate_minItems(current_schema, data, fragments)

# Validate the maximum number of items in an array
def validate_maxItems(current_schema, data, fragments)
if data.is_a?(Array) && (data.nitems > current_schema.schema['maxItems'])
if data.is_a?(Array) && (data.compact.size > current_schema.schema['maxItems'])
message = "The property '#{build_fragment(fragments)}' did not contain a minimum number of items #{current_schema.schema['minItems']}"
raise ValidationError.new(message, fragments, current_schema)
end
Expand Down Expand Up @@ -459,9 +459,9 @@ def validate_ref(current_schema, data, fragments)
# Check for absolute path
path = current_schema.schema['$ref'].split("#")[0]
if path[0,1] == "/"
temp_uri.path = Pathname.new(path).cleanpath
temp_uri.path = Pathname.new(path).cleanpath.to_s
else
temp_uri.path = (Pathname.new(current_schema.uri.path).parent + path).cleanpath
temp_uri.path = (Pathname.new(current_schema.uri.path).parent + path).cleanpath.to_s
end
temp_uri.fragment = current_schema.schema['$ref'].split("#")[1]
end
Expand Down Expand Up @@ -511,9 +511,9 @@ def load_ref_schema(parent_schema,ref)
# Check for absolute path
path = ref.split("#")[0]
if path[0,1] == '/'
uri.path = Pathname.new(path).cleanpath
uri.path = Pathname.new(path).cleanpath.to_s
else
uri.path = (Pathname.new(parent_schema.uri.path).parent + path).cleanpath
uri.path = (Pathname.new(parent_schema.uri.path).parent + path).cleanpath.to_s
end
uri.fragment = nil
end
Expand Down

0 comments on commit 2150840

Please sign in to comment.