Class: Slice
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#alone_in_adjacent_of_type?, #alone_in_container?, #first_adjacent_of_type?, #first_in_container?, #last_adjacent_of_type?, #last_in_container?, #next_slice, #peers, #position_in_adjacent_of_type, #position_in_container, #previous_slice
Instance Attribute Details
#current_page ⇒ Object
Also known as:
page
Returns the value of attribute current_page.
12
13
14
|
# File 'app/models/slice.rb', line 12
def current_page
@current_page
end
|
#renderer ⇒ Object
Returns the value of attribute renderer.
12
13
14
|
# File 'app/models/slice.rb', line 12
def renderer
@renderer
end
|
Class Method Details
.restricted? ⇒ Boolean
19
20
21
|
# File 'app/models/slice.rb', line 19
def self.restricted?
self.restricted == true
end
|
.restricted_slice ⇒ Object
15
16
17
|
# File 'app/models/slice.rb', line 15
def self.restricted_slice
self.restricted = true
end
|
Instance Method Details
#as_json(*args) ⇒ Object
66
67
68
69
70
71
|
# File 'app/models/slice.rb', line 66
def as_json(*args)
attributes.symbolize_keys.except(:_id, :_type).tap do |result|
result.merge!(id: id, type: type)
result.merge!(client_id: client_id) if client_id? && new_record?
end
end
|
#client_id? ⇒ Boolean
54
55
56
|
# File 'app/models/slice.rb', line 54
def client_id?
attributes.include?('client_id')
end
|
#id_or_client_id ⇒ Object
58
59
60
|
# File 'app/models/slice.rb', line 58
def id_or_client_id
client_id? ? client_id : id
end
|
#normal_or_set_page ⇒ Object
37
38
39
|
# File 'app/models/slice.rb', line 37
def normal_or_set_page
normal_page || set_page
end
|
#prepare(params) ⇒ Object
28
29
|
# File 'app/models/slice.rb', line 28
def prepare(params)
end
|
#reference ⇒ Object
50
51
52
|
# File 'app/models/slice.rb', line 50
def reference
[_type, id].join(':')
end
|
#render ⇒ Object
31
32
33
34
35
|
# File 'app/models/slice.rb', line 31
def render
renderer.render_to_string(template_path, locals: {
slice: self
})
end
|
#search_text ⇒ Object
73
74
75
76
77
78
|
# File 'app/models/slice.rb', line 73
def search_text
text_fields = fields.values.select do |field|
(field.type == String) && (field.name !~ /^container$|_id$/)
end
text_fields.map { |field| self[field.name.to_sym] }.join(" ")
end
|
#setup(options) ⇒ Object
23
24
25
26
|
# File 'app/models/slice.rb', line 23
def setup(options)
self.renderer = options[:renderer]
self.current_page = options[:current_page]
end
|
#template_path ⇒ Object
41
42
43
44
|
# File 'app/models/slice.rb', line 41
def template_path
template = (type =~ /_(set|show)$/) ? $1 : 'show'
File.join type.sub(/_show$/, '_set'), 'views', template
end
|
#to_delete? ⇒ Boolean
62
63
64
|
# File 'app/models/slice.rb', line 62
def to_delete?
attributes.include?('_deleted')
end
|
#type ⇒ Object
46
47
48
|
# File 'app/models/slice.rb', line 46
def type
_type.to_s.underscore.gsub(/_slice$/, '')
end
|