Class: Compel::Builder::Schema

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/compel/builder/schema.rb

Direct Known Subclasses

Array, Boolean, Date, DateTime, Float, Hash, Integer, JSON, String, Time

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#default, #length, #required

Constructor Details

#initialize(type) ⇒ Schema

Returns a new instance of Schema.



11
12
13
14
# File 'lib/compel/builder/schema.rb', line 11

def initialize(type)
  @type = type
  @options = Hashie::Mash.new
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/compel/builder/schema.rb', line 8

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/compel/builder/schema.rb', line 8

def type
  @type
end

Instance Method Details

#default_valueObject



20
21
22
# File 'lib/compel/builder/schema.rb', line 20

def default_value
  options[:default]
end

#required?Boolean

Returns:



16
17
18
# File 'lib/compel/builder/schema.rb', line 16

def required?
  !!options[:required]
end

#validate(object) ⇒ Object



24
25
26
# File 'lib/compel/builder/schema.rb', line 24

def validate(object)
  Contract.new(object, self).validate
end