active_record_survey 0.1.18 → 0.1.19
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 316776fa0f2de65dad54cffc746342a4177bd0f8
|
4
|
+
data.tar.gz: da2a911ee4f3c17b012d6105b3d30514750934e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ea0702079cf83209dd6178b146d451eac4de35fc20eb9cc65f57c3fdc6129457c410bbcfbd323bfc2f20b9a9e31a47c90990f372668d64fdbecacb82223c089
|
7
|
+
data.tar.gz: 65812f918dbc7061afff46083d6d419c18a0100ba7f98c1b58654bc8e11efe8b01a4d180860976f5f0beb1d365ee9060f8ede43bed37b71401817ebd11aa7919
|
@@ -1,5 +1,18 @@
|
|
1
1
|
module ActiveRecordSurvey
|
2
2
|
class Node::Answer < Node
|
3
|
+
attr_accessor :ancestor_marked_for_destruction
|
4
|
+
protected :ancestor_marked_for_destruction
|
5
|
+
|
6
|
+
before_save do |node|
|
7
|
+
# ------------------------ WARNING ------------------------
|
8
|
+
# This code is to support #remove_link which uses mark_for_destruction
|
9
|
+
# This code is necessary to clean everything up.
|
10
|
+
# Calling save on this answer won't automatically go to its next_question -> node_maps and clean everything up
|
11
|
+
(@ancestor_marked_for_destruction || []).each { |i|
|
12
|
+
i.destroy
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
3
16
|
# Answer nodes are valid if their questions are valid!
|
4
17
|
# Validate this node against an instance
|
5
18
|
def validate_node(instance)
|
@@ -47,8 +60,19 @@ module ActiveRecordSurvey
|
|
47
60
|
# Removes the link
|
48
61
|
# TODO - does this work when saved??
|
49
62
|
def remove_link
|
50
|
-
|
51
|
-
|
63
|
+
@ancestor_marked_for_destruction ||= []
|
64
|
+
|
65
|
+
self.node_maps.each_with_index { |answer_node_map, answer_node_map_index|
|
66
|
+
answer_node_map.children.each_with_index { |child, child_index|
|
67
|
+
# child.node == question this answer is pointing to
|
68
|
+
child.node.node_maps.each_with_index { |i,ii|
|
69
|
+
# Cleans up all the excess node_maps from the old linkage
|
70
|
+
if ii > 0
|
71
|
+
i.mark_for_destruction
|
72
|
+
@ancestor_marked_for_destruction << i if ii > 0
|
73
|
+
end
|
74
|
+
}
|
75
|
+
|
52
76
|
# Should not know about parent
|
53
77
|
child.parent = nil
|
54
78
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ActiveRecordSurvey
|
2
2
|
class Node < ::ActiveRecord::Base
|
3
3
|
self.table_name = "active_record_survey_nodes"
|
4
|
-
has_many :node_maps, :class_name => "ActiveRecordSurvey::NodeMap", :foreign_key => :active_record_survey_node_id
|
4
|
+
has_many :node_maps, :class_name => "ActiveRecordSurvey::NodeMap", :foreign_key => :active_record_survey_node_id, autosave: true
|
5
5
|
has_many :node_validations, :class_name => "ActiveRecordSurvey::NodeValidation", :foreign_key => :active_record_survey_node_id, autosave: true
|
6
6
|
has_many :instance_nodes, :class_name => "ActiveRecordSurvey::InstanceNode", :foreign_key => :active_record_survey_node_id
|
7
7
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_survey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Butch Marshall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|