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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e80f1e61c2033324b9ff86b0baa996510fd715ca
4
- data.tar.gz: c54065cd9fd75047dde99475e0c8ecfceaed3869
3
+ metadata.gz: f29de2a4c2c5e743506df020087a75c97525d67b
4
+ data.tar.gz: 523efb43fccaca4c0dc966affc470d5ee15f5fc6
5
5
  SHA512:
6
- metadata.gz: 604a6b7d809abc8e93e999c3f406768d9e09826893a7a4b02d4f4ace3300d09124c31720e107b53d9553a9f2cab3ef1b70ddf811fb6123ece5370703d2b3b82e
7
- data.tar.gz: a7cff9333be14be320b779101a68b0acdcf26c968740aa50719120702c9249cefbf1077f898d5df9a2949a3a5ce2cdc4e0d523d99d962b902fea5d4dd56cf197
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
- #=begin
14
- next_answer_nodes = lambda { |node, survey, list|
15
- survey.node_maps.select { |node_map|
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, survey, list)
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, self.survey, []).flatten.uniq
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.includes(:node, parent: [:node])
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.move_to_root
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
- answer_node_map.node
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.includes(:node, parent:[ :node ])
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,3 +1,3 @@
1
1
  module ActiveRecordSurvey
2
- VERSION = "0.1.48"
2
+ VERSION = "0.1.49"
3
3
  end
@@ -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::Answer, :answer_spec => true do
4
6
 
5
7
  describe '#sibling_index' do
@@ -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.48
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-28 00:00:00.000000000 Z
11
+ date: 2016-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord