Class: Pulitzer::Version
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
assoc_name, attrs_name, convert_hash_to_nested
Instance Attribute Details
#processed_element_count ⇒ Object
Returns the value of attribute processed_element_count.
15
16
17
|
# File 'app/models/pulitzer/version.rb', line 15
def processed_element_count
@processed_element_count
end
|
Class Method Details
.convert_nested_assoc(json_hash) ⇒ Object
Instance Method Details
#all_elements ⇒ Object
61
62
63
|
# File 'app/models/pulitzer/version.rb', line 61
def all_elements
(content_elements.to_a + free_form_sections.to_a).sort_by{|e| e.sort_order || 0}
end
|
#content_element(label) ⇒ Object
53
54
55
|
# File 'app/models/pulitzer/version.rb', line 53
def content_element(label)
self.content_elements.to_a.detect{|ce| ce.label == label}
end
|
#empty_required_content_elements? ⇒ Boolean
82
83
84
|
# File 'app/models/pulitzer/version.rb', line 82
def empty_required_content_elements?
content_elements.required.select{|ce| ce.empty_body?}.any? || free_form_sections.includes(partials: :content_elements).map(&:partials).flatten.map(&:content_elements).flatten.select{|ce| ce.empty_body? && ce.required?}.any?
end
|
#has_label(label) ⇒ Object
45
46
47
|
# File 'app/models/pulitzer/version.rb', line 45
def has_label(label)
post_tags.to_a.select{|pt| pt.label_type == label.class.name && pt.label_id == label.id}.any?
end
|
#has_label_type(label_type) ⇒ Object
41
42
43
|
# File 'app/models/pulitzer/version.rb', line 41
def has_label_type(label_type)
post_tags.to_a.select{|pt| pt.label_type == label_type}.any?
end
|
#post_tags_for(label_type) ⇒ Object
49
50
51
|
# File 'app/models/pulitzer/version.rb', line 49
def post_tags_for(label_type)
post_tags.to_a.select{|pt| pt.label_type == label_type}
end
|
#publishable? ⇒ Boolean
78
79
80
|
# File 'app/models/pulitzer/version.rb', line 78
def publishable?
!empty_required_content_elements? && required_partials?
end
|
#required_partials? ⇒ Boolean
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'app/models/pulitzer/version.rb', line 86
def required_partials?
has_all_partials = true
free_form_section_types = post.post_type_version.free_form_section_types
free_form_sections = self.free_form_sections.where(name: free_form_section_types.pluck(:name))
free_form_sections.each do |fs|
free_form_section_type = free_form_section_types.select{|ffst| ffst.name == fs.name }
partial_types = free_form_section_type.first.partial_types
partials = fs.partials.where(label: partial_types.pluck(:label))
has_all_partials = partial_types.all?{|pt| fs.partials.where(post_type_version_id: pt.post_type_version_id).any?}
end
has_all_partials
end
|
#section(name) ⇒ Object
57
58
59
|
# File 'app/models/pulitzer/version.rb', line 57
def section(name)
self.free_form_sections.to_a.detect{|ffs| ffs.name == name}
end
|
#serialize ⇒ Object
73
74
75
76
|
# File 'app/models/pulitzer/version.rb', line 73
def serialize
self.attributes.merge \
processed_element_count: self.processed_element_count
end
|
#template_content_elements ⇒ Object
65
66
67
|
# File 'app/models/pulitzer/version.rb', line 65
def template_content_elements
content_elements.template
end
|
#total_processing_elements ⇒ Object
69
70
71
|
# File 'app/models/pulitzer/version.rb', line 69
def total_processing_elements
active_version.content_elements.count + active_version.post_tags.count + active_version.free_form_sections.count + 2
end
|