active_record_survey 0.1.48 → 0.1.49
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_record_survey/node.rb +7 -24
- data/lib/active_record_survey/node/answer.rb +1 -1
- data/lib/active_record_survey/node/question.rb +7 -11
- data/lib/active_record_survey/survey.rb +2 -5
- data/lib/active_record_survey/version.rb +1 -1
- data/spec/active_record_survey/node/answer_spec.rb +2 -0
- data/spec/active_record_survey/node/question_spec.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f29de2a4c2c5e743506df020087a75c97525d67b
|
4
|
+
data.tar.gz: 523efb43fccaca4c0dc966affc470d5ee15f5fc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb0fa79983055aaaa36330235135caab99885d56a47a15c01577044afb28b8b6c202b23c026248d9fbabe3398c5f3c6137f2bd82dd1fdc6e4c367138a42fed55
|
7
|
+
data.tar.gz: 6438c72f632a066fddc5c492c169659fe00b39d4f20fc41cb446a46db2591bb424a2720ffb5165031c330083cfb3fc05791dc272ec3a10b6b992870c75a2b02e
|
@@ -2,7 +2,7 @@ module ActiveRecordSurvey
|
|
2
2
|
class Node < ::ActiveRecord::Base
|
3
3
|
self.table_name = "active_record_survey_nodes"
|
4
4
|
belongs_to :survey, :class_name => "ActiveRecordSurvey::Survey", :foreign_key => :active_record_survey_id
|
5
|
-
has_many :node_maps, :class_name => "ActiveRecordSurvey::NodeMap", :foreign_key => :active_record_survey_node_id, autosave: true, dependent: :destroy
|
5
|
+
has_many :node_maps, -> { includes(:node, parent: [:node]) }, :class_name => "ActiveRecordSurvey::NodeMap", :foreign_key => :active_record_survey_node_id, autosave: true, dependent: :destroy
|
6
6
|
has_many :node_validations, :class_name => "ActiveRecordSurvey::NodeValidation", :foreign_key => :active_record_survey_node_id, autosave: true, dependent: :destroy
|
7
7
|
has_many :instance_nodes, :class_name => "ActiveRecordSurvey::InstanceNode", :foreign_key => :active_record_survey_node_id
|
8
8
|
|
@@ -10,9 +10,10 @@ module ActiveRecordSurvey
|
|
10
10
|
|
11
11
|
# All the answer nodes that follow from this node
|
12
12
|
def answers
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
nm = self.survey.node_maps
|
14
|
+
|
15
|
+
next_answer_nodes = lambda { |node, list|
|
16
|
+
nm.select { |node_map|
|
16
17
|
!node_map.parent.nil? && node_map.parent.node == node && node_map.node.class.ancestors.include?(::ActiveRecordSurvey::Node::Answer) && !node_map.marked_for_destruction?
|
17
18
|
}.select { |i|
|
18
19
|
!list.include?(i.node)
|
@@ -22,30 +23,12 @@ module ActiveRecordSurvey
|
|
22
23
|
|
23
24
|
list << i.node
|
24
25
|
|
25
|
-
next_answer_nodes.call(i.node,
|
26
|
+
next_answer_nodes.call(i.node, list)
|
26
27
|
}.flatten.uniq
|
27
28
|
|
28
29
|
list
|
29
30
|
}
|
30
|
-
next_answer_nodes.call(self,
|
31
|
-
#=end
|
32
|
-
=begin
|
33
|
-
self.survey.node_maps.select { |i|
|
34
|
-
i.node == self
|
35
|
-
}.collect { |i|
|
36
|
-
# Get all the children from this node
|
37
|
-
i.children
|
38
|
-
}.flatten.collect { |i|
|
39
|
-
# Get the nodes
|
40
|
-
i.node
|
41
|
-
}.select { |i|
|
42
|
-
# Only the nodes that are answers
|
43
|
-
i.class.ancestors.include?(::ActiveRecordSurvey::Node::Answer)
|
44
|
-
}.uniq.collect { |i|
|
45
|
-
i.survey = self.survey # ensure that the survey being referenced by the answers is the original survey - needed for keeping consistent node_maps between build_link and remove_link
|
46
|
-
[i] + i.answers
|
47
|
-
}.flatten.uniq
|
48
|
-
=end
|
31
|
+
next_answer_nodes.call(self, []).flatten.uniq
|
49
32
|
end
|
50
33
|
|
51
34
|
# The instance_node recorded for the passed instance for this node
|
@@ -91,7 +91,7 @@ module ActiveRecordSurvey
|
|
91
91
|
|
92
92
|
# Gets index in sibling relationship
|
93
93
|
def sibling_index
|
94
|
-
node_maps = self.survey.node_maps
|
94
|
+
node_maps = self.survey.node_maps
|
95
95
|
|
96
96
|
if node_map = node_maps.select { |i| i.node == self }.first
|
97
97
|
parent = node_map.parent
|
@@ -20,19 +20,15 @@ module ActiveRecordSurvey
|
|
20
20
|
i.node == answer
|
21
21
|
}
|
22
22
|
}.flatten.uniq.collect { |answer_node_map|
|
23
|
-
answer_node_map.
|
24
|
-
answer_node_map.survey = self.survey
|
25
|
-
|
26
|
-
answer_node_map
|
27
|
-
}.collect { |answer_node_map|
|
28
|
-
answer_node_map.node.type = klass.to_s
|
29
|
-
answer_node_map.node = answer_node_map.node.becomes(klass)
|
30
|
-
answer_node_map.node.survey = self.survey
|
31
|
-
answer_node_map.node.save
|
32
|
-
|
23
|
+
node = answer_node_map.node
|
33
24
|
answer_node_map.send((answer_node_map.new_record?)? :destroy : :mark_for_destruction)
|
25
|
+
node
|
26
|
+
}.collect { |answer|
|
27
|
+
answer.type = klass.to_s
|
28
|
+
answer = answer.becomes(klass)
|
29
|
+
answer.save if !answer.new_record?
|
34
30
|
|
35
|
-
|
31
|
+
answer
|
36
32
|
}.uniq
|
37
33
|
|
38
34
|
answers.each { |answer|
|
@@ -1,12 +1,10 @@
|
|
1
1
|
module ActiveRecordSurvey
|
2
2
|
class Survey < ::ActiveRecord::Base
|
3
3
|
self.table_name = "active_record_surveys"
|
4
|
-
has_many :node_maps, :class_name => "ActiveRecordSurvey::NodeMap", :foreign_key => :active_record_survey_id, autosave: true
|
4
|
+
has_many :node_maps, -> { includes(:node, parent: [:node]) }, :class_name => "ActiveRecordSurvey::NodeMap", :foreign_key => :active_record_survey_id, autosave: true
|
5
5
|
has_many :nodes, :class_name => "ActiveRecordSurvey::Node", :foreign_key => :active_record_survey_id
|
6
6
|
has_many :questions, :class_name => "ActiveRecordSurvey::Node::Question", :foreign_key => :active_record_survey_id
|
7
7
|
|
8
|
-
default_scope { includes(node_maps:[:node,parent:[:node]]) }
|
9
|
-
|
10
8
|
def root_node
|
11
9
|
self.node_maps.includes(:node).select { |i| i.depth === 0 }.first
|
12
10
|
end
|
@@ -28,8 +26,7 @@ module ActiveRecordSurvey
|
|
28
26
|
|
29
27
|
# All the connective edges
|
30
28
|
def edges
|
31
|
-
self.node_maps.
|
32
|
-
.select { |i| !i.marked_for_destruction? }.select { |i|
|
29
|
+
self.node_maps.select { |i| !i.marked_for_destruction? }.select { |i|
|
33
30
|
i.node && i.parent
|
34
31
|
}.collect { |i|
|
35
32
|
{
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
#ActiveRecord::Base.logger = Logger.new(STDOUT) if defined?(ActiveRecord::Base)
|
4
|
+
|
3
5
|
describe ActiveRecordSurvey::Node::Question, :question_spec => true do
|
4
6
|
describe "#before_destroy_rebuild_node_map" do
|
5
7
|
it 'should not relink any following questions' do
|
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.49
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Butch Marshall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|