Class: Compel::Builder::Schema

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

Direct Known Subclasses

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#default, #is, #length, #max_length, #min_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 = default_options
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

Class Method Details

.human_nameObject



30
31
32
# File 'lib/compel/builder/schema.rb', line 30

def human_name
  "#{self.name.split('::')[1..-1].join('::')}"
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