Class: PushType::FieldType
Direct Known Subclasses
BooleanField, DateField, MarkdownField, MatrixField, NumberField, RelationField, RepeaterField, SelectField, StringField, StructureField, TagListField, TextField, TimeField, WysiwygField
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, model, opts = {}) ⇒ FieldType
Returns a new instance of FieldType.
29
30
31
32
33
|
# File 'lib/push_type/field_type.rb', line 29
def initialize(name, model, opts = {})
@name = name
@model = model
@opts = [defaults, self.class.options, opts].compact.inject(&:deep_merge)
end
|
Class Attribute Details
.def_block ⇒ Object
Returns the value of attribute def_block.
12
13
14
|
# File 'lib/push_type/field_type.rb', line 12
def def_block
@def_block
end
|
.init_block ⇒ Object
Returns the value of attribute init_block.
12
13
14
|
# File 'lib/push_type/field_type.rb', line 12
def init_block
@init_block
end
|
Instance Attribute Details
Returns the value of attribute model.
27
28
29
|
# File 'lib/push_type/field_type.rb', line 27
def model
@model
end
|
Returns the value of attribute name.
27
28
29
|
# File 'lib/push_type/field_type.rb', line 27
def name
@name
end
|
Class Method Details
.on_class(&block) ⇒ Object
18
19
20
|
# File 'lib/push_type/field_type.rb', line 18
def on_class(&block)
@def_block = block
end
|
.on_instance(&block) ⇒ Object
22
23
24
|
# File 'lib/push_type/field_type.rb', line 22
def on_instance(&block)
@init_block = block
end
|
.options(opts = {}) ⇒ Object
14
15
16
|
# File 'lib/push_type/field_type.rb', line 14
def options(opts = {})
@options ||= opts
end
|
Instance Method Details
#css_class ⇒ Object
59
60
61
|
# File 'lib/push_type/field_type.rb', line 59
def css_class
@opts[:css_class]
end
|
#field_options ⇒ Object
79
80
81
|
# File 'lib/push_type/field_type.rb', line 79
def field_options
@opts[:field_options]
end
|
71
72
73
|
# File 'lib/push_type/field_type.rb', line 71
def form_helper
@opts[:form_helper]
end
|
#html_options ⇒ Object
75
76
77
|
# File 'lib/push_type/field_type.rb', line 75
def html_options
@opts[:html_options]
end
|
#json_primitive ⇒ Object
55
56
57
|
# File 'lib/push_type/field_type.rb', line 55
def json_primitive
@opts[:json_primitive]
end
|
#json_value ⇒ Object
47
48
49
|
# File 'lib/push_type/field_type.rb', line 47
def json_value
model.field_store.try(:[], name.to_s)
end
|
35
36
37
|
# File 'lib/push_type/field_type.rb', line 35
def kind
self.class.name.demodulize.underscore.gsub(/_(field|type)$/, '').to_sym
end
|
67
68
69
|
# File 'lib/push_type/field_type.rb', line 67
def label
@opts[:label]
end
|
#multiple? ⇒ Boolean
83
84
85
|
# File 'lib/push_type/field_type.rb', line 83
def multiple?
@opts[:multiple]
end
|
#primitive ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/push_type/field_type.rb', line 39
def primitive
begin
"push_type/primitives/#{ json_primitive }_type".camelize.constantize
rescue NameError
"#{ json_primitive }_type".camelize.constantize
end
end
|
63
64
65
|
# File 'lib/push_type/field_type.rb', line 63
def template
@opts[:template]
end
|
51
52
53
|
# File 'lib/push_type/field_type.rb', line 51
def value
json_value
end
|