Class: Schemacop::V3::BooleanNode

Inherits:
Node
  • Object
show all
Defined in:
lib/schemacop/v3/boolean_node.rb

Instance Attribute Summary

Attributes inherited from Node

#as, #default, #description, #name, #options, #parent, #require_key, #title

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#children, #create, create, dsl_methods, #dsl_node, #dsl_scm, #init, #initialize, #require_key?, #required?, resolve_class, #schemas, supports_children, supports_children_options, #used_external_schemas, #validate

Constructor Details

This class inherits a constructor from Schemacop::V3::Node

Class Method Details

.allowed_optionsObject



23
24
25
# File 'lib/schemacop/v3/boolean_node.rb', line 23

def self.allowed_options
  super + %i[cast_str]
end

Instance Method Details

#allowed_typesObject



8
9
10
11
12
13
# File 'lib/schemacop/v3/boolean_node.rb', line 8

def allowed_types
  {
    TrueClass  => :boolean,
    FalseClass => :boolean
  }
end

#as_jsonObject



4
5
6
# File 'lib/schemacop/v3/boolean_node.rb', line 4

def as_json
  process_json([], type: :boolean)
end

#cast(value) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/schemacop/v3/boolean_node.rb', line 15

def cast(value)
  if value.is_a?(TrueClass) || value.is_a?(FalseClass)
    value
  else
    default
  end
end