Skip to content

Commit

Permalink
Merge pull request #130 from iainbeeston/refactor_slightly
Browse files Browse the repository at this point in the history
Refactor classes and validator accessor methods
  • Loading branch information
hoxworth committed Sep 29, 2014
2 parents bf0cde9 + 47ddd7b commit 758055c
Show file tree
Hide file tree
Showing 47 changed files with 250 additions and 158 deletions.
27 changes: 27 additions & 0 deletions lib/json-schema/attribute.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'json-schema/errors/validation_error'

module JSON
class Schema
class Attribute
def self.validate(current_schema, data, fragments, processor, validator, options = {})
end

def self.build_fragment(fragments)
"#/#{fragments.join('/')}"
end

def self.validation_error(processor, message, fragments, current_schema, failed_attribute, record_errors)
error = ValidationError.new(message, fragments, failed_attribute, current_schema)
if record_errors
processor.validation_error(error)
else
raise error
end
end

def self.validation_errors(validator)
validator.validation_errors
end
end
end
end
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/additionalitems.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class AdditionalItemsAttribute < Attribute
Expand All @@ -20,4 +22,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/json-schema/attributes/additionalproperties.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'json-schema/attribute'
require 'json-schema/attributes/extends'

module JSON
Expand Down
2 changes: 2 additions & 0 deletions lib/json-schema/attributes/allof.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class AllOfAttribute < Attribute
Expand Down
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/anyof.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class AnyOfAttribute < Attribute
Expand Down Expand Up @@ -38,4 +40,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/dependencies.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class DependenciesAttribute < Attribute
Expand Down Expand Up @@ -27,4 +29,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/dependencies_v4.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class DependenciesV4Attribute < Attribute
Expand All @@ -17,4 +19,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/disallow.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class DisallowAttribute < Attribute
Expand All @@ -8,4 +10,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/divisibleby.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class DivisibleByAttribute < Attribute
Expand All @@ -13,4 +15,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/enum.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class EnumAttribute < Attribute
Expand All @@ -21,4 +23,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/json-schema/attributes/extends.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'json-schema/attribute'
require 'json-schema/attributes/ref'

module JSON
Expand Down
1 change: 1 addition & 0 deletions lib/json-schema/attributes/format.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'json-schema/attribute'
require 'uri'

module JSON
Expand Down
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/items.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class ItemsAttribute < Attribute
Expand All @@ -22,4 +24,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/maxdecimal.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class MaxDecimalAttribute < Attribute
Expand All @@ -12,4 +14,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/maximum.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class MaximumAttribute < Attribute
Expand All @@ -12,4 +14,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
2 changes: 2 additions & 0 deletions lib/json-schema/attributes/maximum_inclusive.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class MaximumInclusiveAttribute < Attribute
Expand Down
2 changes: 2 additions & 0 deletions lib/json-schema/attributes/maxitems.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class MaxItemsAttribute < Attribute
Expand Down
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/maxlength.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class MaxLengthAttribute < Attribute
Expand All @@ -11,4 +13,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/maxproperties.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class MaxPropertiesAttribute < Attribute
Expand All @@ -9,4 +11,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/minimum.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class MinimumAttribute < Attribute
Expand All @@ -12,4 +14,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/minimum_inclusive.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class MinimumInclusiveAttribute < Attribute
Expand All @@ -12,4 +14,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/minitems.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class MinItemsAttribute < Attribute
Expand All @@ -9,4 +11,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/minlength.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class MinLengthAttribute < Attribute
Expand All @@ -11,4 +13,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/minproperties.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class MinPropertiesAttribute < Attribute
Expand All @@ -9,4 +11,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/multipleof.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class MultipleOfAttribute < Attribute
Expand All @@ -13,4 +15,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/not.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class NotAttribute < Attribute
Expand Down Expand Up @@ -25,4 +27,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
2 changes: 2 additions & 0 deletions lib/json-schema/attributes/oneof.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class OneOfAttribute < Attribute
Expand Down
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/pattern.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class PatternAttribute < Attribute
Expand All @@ -12,4 +14,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/patternproperties.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class PatternPropertiesAttribute < Attribute
Expand All @@ -20,4 +22,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
2 changes: 2 additions & 0 deletions lib/json-schema/attributes/properties.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class PropertiesAttribute < Attribute
Expand Down
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/properties_optional.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class PropertiesOptionalAttribute < Attribute
Expand All @@ -20,4 +22,4 @@ def self.validate(current_schema, data, fragments, processor, validator, options
end
end
end
end
end
2 changes: 2 additions & 0 deletions lib/json-schema/attributes/properties_v4.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class PropertiesV4Attribute < Attribute
Expand Down
3 changes: 3 additions & 0 deletions lib/json-schema/attributes/ref.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require 'json-schema/attribute'
require 'json-schema/errors/schema_error'

module JSON
class Schema
class RefAttribute < Attribute
Expand Down
2 changes: 2 additions & 0 deletions lib/json-schema/attributes/required.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class RequiredAttribute < Attribute
Expand Down
2 changes: 2 additions & 0 deletions lib/json-schema/attributes/type.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class TypeAttribute < Attribute
Expand Down
4 changes: 3 additions & 1 deletion lib/json-schema/attributes/type_v4.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json-schema/attribute'

module JSON
class Schema
class TypeV4Attribute < Attribute
Expand Down Expand Up @@ -51,4 +53,4 @@ def self.data_valid_for_type?(data, type)
end
end
end
end
end

0 comments on commit 758055c

Please sign in to comment.