Class: Workarea::Content::Field
- Inherits:
-
Object
- Object
- Workarea::Content::Field
show all
- Defined in:
- app/models/workarea/content/field.rb
Direct Known Subclasses
Workarea::Content::Fields::Asset, Workarea::Content::Fields::Boolean, Workarea::Content::Fields::Category, Workarea::Content::Fields::Color, Workarea::Content::Fields::HiddenBreakpoints, Workarea::Content::Fields::Integer, Workarea::Content::Fields::Options, Workarea::Content::Fields::Products, Workarea::Content::Fields::Range, Workarea::Content::Fields::String, Workarea::Content::Fields::Taxonomy, Workarea::Content::Fields::Text, Workarea::Content::Fields::Url
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, options = {}) ⇒ Field
Returns a new instance of Field.
6
7
8
9
|
# File 'app/models/workarea/content/field.rb', line 6
def initialize(name, options = {})
@name = name
@options = options
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4
5
6
|
# File 'app/models/workarea/content/field.rb', line 4
def name
@name
end
|
#options ⇒ Object
Returns the value of attribute options.
4
5
6
|
# File 'app/models/workarea/content/field.rb', line 4
def options
@options
end
|
Instance Method Details
#default ⇒ Object
19
20
21
22
23
24
25
|
# File 'app/models/workarea/content/field.rb', line 19
def default
if options[:default].respond_to?(:call)
options[:default].call
else
options[:default]
end
end
|
#note ⇒ Object
40
41
42
|
# File 'app/models/workarea/content/field.rb', line 40
def note
options[:note]
end
|
#partial ⇒ Object
27
28
29
30
|
# File 'app/models/workarea/content/field.rb', line 27
def partial
options[:partial].presence ||
self.class.name.demodulize.underscore.systemize
end
|
#required? ⇒ Boolean
32
33
34
|
# File 'app/models/workarea/content/field.rb', line 32
def required?
!!options[:required]
end
|
#slug ⇒ Object
11
12
13
|
# File 'app/models/workarea/content/field.rb', line 11
def slug
name.to_s.systemize.to_sym
end
|
44
45
46
|
# File 'app/models/workarea/content/field.rb', line 44
def tooltip
options[:tooltip]
end
|
#type ⇒ Object
15
16
17
|
# File 'app/models/workarea/content/field.rb', line 15
def type
self.class.name.demodulize.systemize.to_sym
end
|
#typecast(value) ⇒ Object
36
37
38
|
# File 'app/models/workarea/content/field.rb', line 36
def typecast(value)
value.to_s
end
|