Class: Jschematic::Attributes::Disallow

Inherits:
Type
  • Object
show all
Defined in:
lib/jschematic/attributes/disallow.rb

Instance Attribute Summary

Attributes inherited from Type

#type

Attributes included from Element

#id, #parent

Instance Method Summary collapse

Methods inherited from Type

#initialize

Methods included from Element

#required?, #schema_for, #title, #to_s

Constructor Details

This class inherits a constructor from Jschematic::Attributes::Type

Instance Method Details

#accepts?(instance) ⇒ Boolean

disallow inverts the type attribute, so it succeeds if type fails

Returns:

  • (Boolean)


5
6
7
8
9
10
11
12
13
# File 'lib/jschematic/attributes/disallow.rb', line 5

def accepts?(instance)
  inverted = begin
    super
    false
  rescue ValidationError
    true
  end
  inverted || fail_validation!("instance not to be of type '#{type}'", instance)
end