Class: Schemacop::BaseSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/schemacop/base_schema.rb

Direct Known Subclasses

Schema2, Schema3

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



3
4
5
# File 'lib/schemacop/base_schema.rb', line 3

def root
  @root
end

Instance Method Details

#invalid?(data) ⇒ Boolean

Query data validity

Parameters:

  • data

    The data to validate.

Returns:

  • (Boolean)

    True if data is invalid, false otherwise.



17
18
19
# File 'lib/schemacop/base_schema.rb', line 17

def invalid?(data)
  !valid?(data)
end

#valid?(data) ⇒ Boolean

Query data validity

Parameters:

  • data

    The data to validate.

Returns:

  • (Boolean)

    True if the data is valid, false otherwise.



9
10
11
# File 'lib/schemacop/base_schema.rb', line 9

def valid?(data)
  validate(data).valid?
end

#validate!(data) ⇒ Object

Validate data for the defined Schema

Parameters:

  • data

    The data to validate.

Returns:

  • The processed data

Raises:



27
28
29
30
31
32
33
34
35
# File 'lib/schemacop/base_schema.rb', line 27

def validate!(data)
  result = validate(data)

  unless result.valid?
    fail Exceptions::ValidationError, result.exception_message
  end

  return result.data
end