active_record_survey 0.1.18 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc22ee8242273415952e25ab1c2dd47f8c92275e
4
- data.tar.gz: c0896bfda37bc9df6705a27237ad2696d0bf087e
3
+ metadata.gz: 316776fa0f2de65dad54cffc746342a4177bd0f8
4
+ data.tar.gz: da2a911ee4f3c17b012d6105b3d30514750934e2
5
5
  SHA512:
6
- metadata.gz: 222b0693802954fa9367b349b4da5f087b46b42509cdbbc01ad978346b5d07c6468f3ac9b7b2ef31b3d5aa508a2f1f04e1530b944e6fe84d20ea691f9ccc6a91
7
- data.tar.gz: fe9ac6b5e0793761e0fa13f0c6b925d48f768374409ab18455058d42830f537ec6e8279f43d26357ba3dabab93c6424ab184ea7c070ade78e4d92242061aaf71
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
- self.node_maps.each { |answer_node_map|
51
- answer_node_map.children.each { |child|
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
 
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordSurvey
2
- VERSION = "0.1.18"
2
+ VERSION = "0.1.19"
3
3
  end
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.18
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-28 00:00:00.000000000 Z
11
+ date: 2015-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord