Class: ContentsCore::Item
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.item_types ⇒ Object
53
54
55
|
# File 'app/models/contents_core/item.rb', line 53
def self.item_types
@@item_types ||= ContentsCore.config[:items].keys.map( &:to_s )
end
|
.permitted_attributes ⇒ Object
57
58
59
|
# File 'app/models/contents_core/item.rb', line 57
def self.permitted_attributes
[ :data_boolean, :data_datetime, :data_file, :data_float, :data_hash, :data_integer, :data_string, :data_text ]
end
|
Instance Method Details
#as_json(options = nil) ⇒ Object
9
10
11
|
# File 'app/models/contents_core/item.rb', line 9
def as_json( options = nil )
super( {only: [:id, :name, :type], methods: [:data]}.merge(options || {}) )
end
|
#attr_id ⇒ Object
13
14
15
|
# File 'app/models/contents_core/item.rb', line 13
def attr_id
"#{self.class_name}-#{self.id}"
end
|
#class_name ⇒ Object
17
18
19
|
# File 'app/models/contents_core/item.rb', line 17
def class_name
self.class.to_s.split('::').last
end
|
#config ⇒ Object
61
62
63
|
# File 'app/models/contents_core/item.rb', line 61
def config
@config ||= self.block && self.block.config[:options] && self.block.config[:options][self.name.to_sym] ? self.block.config[:options][self.name.to_sym] : ( ContentsCore.config[:items][self.class::type_name.to_sym] ? ContentsCore.config[:items][self.class::type_name.to_sym] : {} )
end
|
#data_type ⇒ Object
65
66
67
|
# File 'app/models/contents_core/item.rb', line 65
def data_type
@data_type ||= ( config[:data_type] || :string ).to_sym
end
|
#editable ⇒ Object
21
22
23
|
# File 'app/models/contents_core/item.rb', line 21
def editable
ContentsCore.editing ? " data-ec-item=\"#{self.id}\" data-ec-input=\"#{self.opt_input}\" data-ec-type=\"#{self.class_name}\"".html_safe : ''
end
|
25
26
27
28
29
30
31
32
33
|
# File 'app/models/contents_core/item.rb', line 25
def opt_input
if self.block.options[self.name] && self.block.options[self.name]['input']
self.block.options[self.name]['input'].to_s
elsif config[:input]
config[:input].to_s
else
''
end
end
|
#process_data(args = nil) ⇒ Object
35
36
37
|
# File 'app/models/contents_core/item.rb', line 35
def process_data( args = nil )
config[:process_data].call( self.data, args ) if config[:process_data]
end
|
#set(value) ⇒ Object
39
40
41
42
|
# File 'app/models/contents_core/item.rb', line 39
def set( value )
self.data = value
self
end
|
#to_s ⇒ Object
44
45
46
|
# File 'app/models/contents_core/item.rb', line 44
def to_s
self.data
end
|
#update_data(value) ⇒ Object
48
49
50
51
|
# File 'app/models/contents_core/item.rb', line 48
def update_data( value )
self.data = value
self.save
end
|