Class: SimpleSmartAnswerEdition
- Inherits:
-
Edition
- Object
- Edition
- SimpleSmartAnswerEdition
show all
- Includes:
- Mongoid::Document
- Defined in:
- app/models/simple_smart_answer_edition.rb,
app/models/simple_smart_answer_edition/node.rb,
app/models/simple_smart_answer_edition/node/option.rb
Defined Under Namespace
Classes: Node
Constant Summary
collapse
- GOVSPEAK_FIELDS =
[:body]
Instance Method Summary
collapse
Methods inherited from Edition
#artefact, #broadcast_action, #can_create_new_edition?, #check_for_archived_artefact, #clone_whole_body_from, #cloning_between_parted_types?, #destroy_artefact, #fields_to_copy, find_and_identify, find_or_create_from_panopticon_data, #first_edition_of_published, #format, #format_name, #get_next_version_number, #has_ever_been_published?, #has_sibling_in_progress?, #has_video?, #history, #in_progress_sibling, #indexable_content, #indexable_content_with_parts, #indexable_content_without_parts, #latest_change_note, #latest_edition?, #latest_major_update, #major_updates_in_series, #meta_data, #previous_published_edition, #previous_siblings, #public_updated_at, #published_edition, #retired_format?, #safe_to_preview?, #series, #siblings, #subsequent_siblings, #update_slug_from_artefact, #was_published
Methods included from Workflow
#can_destroy?, #check_can_delete_and_notify, #denormalise_users!, #error_description, #fact_checked?, #important_note, #in_progress?, #locked_for_edits?, #mark_as_rejected, #notify_siblings_of_new_edition, #perform_event_without_validations, #previous_edition, #status_text
Instance Method Details
#build_clone(target_class = nil) ⇒ Object
27
28
29
30
31
32
33
34
35
|
# File 'app/models/simple_smart_answer_edition.rb', line 27
def build_clone(target_class=nil)
new_edition = super(target_class)
if new_edition.is_a?(SimpleSmartAnswerEdition)
self.nodes.each {|n| new_edition.nodes << n.clone }
end
new_edition
end
|
#destroy_in_attrs?(attrs) ⇒ Boolean
68
69
70
|
# File 'app/models/simple_smart_answer_edition.rb', line 68
def destroy_in_attrs?(attrs)
attrs.delete('_destroy') == '1'
end
|
#initial_node ⇒ Object
64
65
66
|
# File 'app/models/simple_smart_answer_edition.rb', line 64
def initial_node
self.nodes.first
end
|
#original_update_attributes ⇒ Object
Workaround mongoid conflicting mods error See jira.mongodb.org/browse/MONGOID-1220 Override update_attributes so that nested nodes are updated individually. This get around the problem of mongoid issuing a query with conflicting modifications to the same document.
43
|
# File 'app/models/simple_smart_answer_edition.rb', line 43
alias_method :original_update_attributes, :update_attributes
|
#update_attributes(attributes) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'app/models/simple_smart_answer_edition.rb', line 45
def update_attributes(attributes)
if nodes_attrs = attributes.delete(:nodes_attributes)
nodes_attrs.each do |index, node_attrs|
if node_id = node_attrs['id']
node = nodes.find(node_id)
if destroy_in_attrs?(node_attrs)
node.destroy
else
node.update_attributes(node_attrs)
end
else
nodes << Node.new(node_attrs) unless destroy_in_attrs?(node_attrs)
end
end
end
original_update_attributes(attributes)
end
|
#whole_body ⇒ Object
19
20
21
22
23
24
25
|
# File 'app/models/simple_smart_answer_edition.rb', line 19
def whole_body
parts = [body]
unless nodes.nil?
parts += nodes.map { |node| "#{node.kind}: #{node.title} \n\n #{node.body}" }
end
parts.join("\n\n\n")
end
|