Class: Jschematic::Attributes::Required
- Inherits:
-
Object
- Object
- Jschematic::Attributes::Required
show all
- Includes:
- Element
- Defined in:
- lib/jschematic/attributes/required.rb
Instance Attribute Summary
Attributes included from Element
#id, #parent
Instance Method Summary
collapse
Methods included from Element
#schema_for, #title, #to_s
Constructor Details
#initialize(required = false) ⇒ Required
Returns a new instance of Required.
8
9
10
11
12
13
14
15
|
# File 'lib/jschematic/attributes/required.rb', line 8
def initialize(required=false)
case required
when TrueClass, FalseClass
@required = required
else
raise "Require must be strictly true or false. Truthy and false values are not allowed."
end
end
|
Instance Method Details
#accepts?(instance) ⇒ Boolean
21
22
23
24
25
26
27
|
# File 'lib/jschematic/attributes/required.rb', line 21
def accepts?(instance)
if @required
instance || fail_validation!(@required, instance)
else
true
end
end
|
#required? ⇒ Boolean
17
18
19
|
# File 'lib/jschematic/attributes/required.rb', line 17
def required?
@required
end
|