Class: Compel::Builder::Schema
- Inherits:
-
Object
- Object
- Compel::Builder::Schema
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
#coerce_if_proc, #default, #if, #is, #length, #max_length, #min_length, #required
Constructor Details
#initialize(type) ⇒ Schema
Returns a new instance of Schema.
15
16
17
18
|
# File 'lib/compel/builder/schema.rb', line 15
def initialize(type)
@type = type
@options = default_options
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
8
9
10
|
# File 'lib/compel/builder/schema.rb', line 8
def options
@options
end
|
#type ⇒ Object
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_name ⇒ Object
11
12
13
|
# File 'lib/compel/builder/schema.rb', line 11
def self.human_name
"#{self.name.split('::')[1..-1].join('::')}"
end
|
Instance Method Details
#build_option(name, value, extra_options = {}) ⇒ Object
32
33
34
35
36
|
# File 'lib/compel/builder/schema.rb', line 32
def build_option(name, value, = {})
options[name] = { value: value }.merge()
self
end
|
#default_options ⇒ Object
38
39
40
|
# File 'lib/compel/builder/schema.rb', line 38
def default_options
{ required: { value: false } }
end
|
#default_value ⇒ Object
24
25
26
|
# File 'lib/compel/builder/schema.rb', line 24
def default_value
options[:default][:value] if options[:default]
end
|
20
21
22
|
# File 'lib/compel/builder/schema.rb', line 20
def required?
options[:required][:value]
end
|
#validate(object) ⇒ Object
28
29
30
|
# File 'lib/compel/builder/schema.rb', line 28
def validate(object)
Contract.new(object, self).validate
end
|