active_record_survey-node_map_group 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f6053a163eb9d9b0b312efb6af7b83a27eb8537b
4
+ data.tar.gz: 5b4adb626a63f60f5528061f2cdf44afbfd194a4
5
+ SHA512:
6
+ metadata.gz: d0dfc59fe30965ff22e78ab167df4ff4e46cd8b1f426db059f00f9e62254b4b29653e5c695568c9667cfe26d8ecb5d2ed459b553877346d76a2a7c356a0369da
7
+ data.tar.gz: 1531ebb62bae46f104095deec4afb4a288a36fe0b806c9dba1631b4a37abcf2228adb246c0715c5e8250c90d53160514b28ee27031b0bfbf96c9a54caaa509b8
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
4
+ - 2.0.0
5
+ - 1.9.3
6
+ script: rspec spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_record_survey-node_map_group.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ [![Gem Version](https://badge.fury.io/rb/active_record_survey-node_map_group.svg)](http://badge.fury.io/rb/active_record_survey-node_map_group)
2
+ [![Build Status](https://travis-ci.org/butchmarshall/active_record_survey-node_map_group.svg?branch=master)](https://travis-ci.org/butchmarshall/active_record_survey-node_map_group)
3
+
4
+ # ActiveRecordSurvey::NodeMapGroup
5
+
6
+ Group `ActiveRecordSurvey::NodeMap`'s together with `ActiveRecordSurvey::NodeMapGroup`.
7
+
8
+ Release Notes
9
+ ============
10
+
11
+ **0.0.1**
12
+ - Initial commit
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'active_record_survey-node_map_group'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install active_record_survey-node_map_group
27
+
28
+ ## Installation
29
+
30
+ ```ruby
31
+ rails generate active_record_survey-node_map_group:active_record
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ TODO
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+
42
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/butchmarshall/active_record_survey.
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
51
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_record_survey/node_map_group/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_record_survey-node_map_group"
8
+ spec.version = ActiveRecordSurvey::NodeMapGroup::VERSION
9
+ spec.authors = ["Butch Marshall"]
10
+ spec.email = ["butch.a.marshall@gmail.com"]
11
+ spec.summary = "ActiveRecordSurvey NodeMap groups"
12
+ spec.description = "Create groupings of ActiveRecordSurvey branching paths with ActiveRecordSurvey::NodeMapGroup"
13
+ spec.homepage = "https://github.com/butchmarshall/active_record_survey-node_map_group"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "active_record_survey", ">= 0.1.38"
22
+
23
+ if RUBY_PLATFORM == 'java'
24
+ spec.add_development_dependency "jdbc-sqlite3", "> 0"
25
+ spec.add_development_dependency "activerecord-jdbcsqlite3-adapter", "> 0"
26
+ else
27
+ spec.add_development_dependency "sqlite3", "> 0"
28
+ end
29
+
30
+ spec.add_development_dependency "database_cleaner"
31
+ spec.add_development_dependency "factory_girl", "> 4.0"
32
+ spec.add_development_dependency "bundler", "~> 1.11"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_record_survey/node_map_group"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,17 @@
1
+ require "active_support"
2
+ require "active_support/dependencies"
3
+ require "active_record"
4
+
5
+ require "active_record_survey"
6
+ require "active_record_survey/node_map_group/version"
7
+
8
+ require "active_record_survey/node_map_group/class_methods"
9
+ require "active_record_survey/node_map_group/instance_methods"
10
+
11
+ module ActiveRecordSurvey
12
+ class NodeMapGroup < ActiveRecord::Base
13
+ end
14
+ end
15
+
16
+ ActiveRecordSurvey::NodeMapGroup.send :include, ActiveRecordSurvey::NodeMapGroup::InstanceMethods
17
+ ActiveRecordSurvey::NodeMapGroup.send :extend, ActiveRecordSurvey::NodeMapGroup::ClassMethods
@@ -0,0 +1,12 @@
1
+ module ActiveRecordSurvey
2
+ class NodeMapGroup < ActiveRecord::Base
3
+ module ClassMethods
4
+ def self.extended(base)
5
+ base.has_many :node_maps, :class_name => "ActiveRecordSurvey::NodeMap", :foreign_key => :active_record_survey_api_node_map_group_id
6
+ base.belongs_to :survey, :class_name => "ActiveRecordSurvey::Survey", :foreign_key => :active_record_survey_id
7
+ base.validates_presence_of :survey
8
+ base.validate :validate_node_maps
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,29 @@
1
+ require 'active_record_survey/node_map_group/version'
2
+
3
+ module ActiveRecordSurvey
4
+ class NodeMapGroup < ActiveRecord::Base
5
+ module Compatibility
6
+ if ActiveSupport::VERSION::MAJOR >= 4
7
+ require 'active_support/proxy_object'
8
+
9
+ def self.executable_prefix
10
+ 'bin'
11
+ end
12
+
13
+ def self.proxy_object_class
14
+ ActiveSupport::ProxyObject
15
+ end
16
+ else
17
+ require 'active_support/basic_object'
18
+
19
+ def self.executable_prefix
20
+ 'script'
21
+ end
22
+
23
+ def self.proxy_object_class
24
+ ActiveSupport::BasicObject
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,58 @@
1
+ module ActiveRecordSurvey
2
+ class NodeMapGroup < ActiveRecord::Base
3
+ module InstanceMethods
4
+ def self.included(base)
5
+ base.table_name = :active_record_survey_api_node_map_groups
6
+ end
7
+
8
+ # Adds a question to the page
9
+ # @param [Object] Question object to add
10
+ # @param [Object] The answer to get to the question
11
+ # @return [Boolean] Whether the operation was successful
12
+ def build_question(question, previous_answer = nil)
13
+ results = self.survey.node_maps.select { |i|
14
+ i.node === question && ((previous_answer.nil?)? true : i.parent && i.parent.node == previous_answer)
15
+ }.collect { |question_node|
16
+ if self.send(:node_map_valid?, question_node)
17
+ self.node_maps << question_node
18
+ true
19
+ else
20
+ false
21
+ end
22
+ }
23
+
24
+ # At least one node_map was valid
25
+ (results.length > 0 && !results.include?(false))
26
+ end
27
+
28
+ private
29
+ def validate_node_maps
30
+ self.node_maps.each { |node_map|
31
+ if !self.send(:node_map_valid?, node_map)
32
+ errors[:base] << "INVALID_NODE_MAP"
33
+ end
34
+ }
35
+ end
36
+
37
+ # Whether this node map is valid
38
+ def node_map_valid?(potential_node_map)
39
+ # Nothing else added - so yep - valid!
40
+ return true if self.node_maps.length === 0
41
+
42
+ # The node map shares a node already added
43
+ return true if self.node_maps.collect { |nm| nm.node == potential_node_map.node }.include?(true)
44
+
45
+ # There is an existing node where:
46
+ # - There is only one next question possible from it
47
+ # - This node is that next question
48
+ return true if self.node_maps.collect { |node_map|
49
+ next_question = node_map.node.next_questions;
50
+ (next_question.length === 1 && next_question.include?(potential_node_map.node))
51
+ }.include?(true)
52
+
53
+ # No criteria match - not valid
54
+ false
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,7 @@
1
+ require "active_record"
2
+
3
+ module ActiveRecordSurvey
4
+ class NodeMapGroup < ActiveRecord::Base
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ require "generators/active_record_survey/node_map_group/active_record_survey_node_map_group_generator"
2
+ require "generators/active_record_survey/node_map_group/next_migration_version"
3
+ require "rails/generators/migration"
4
+ require "rails/generators/active_record"
5
+
6
+ # Extend the HasDynamicColumnsGenerator so that it creates an AR migration
7
+ module ActiveRecordSurvey
8
+ class NodeMapGroup < ActiveRecord::Base
9
+ class ActiveRecordGenerator < ::ActiveRecordSurveyGenerator
10
+ include Rails::Generators::Migration
11
+ extend NextMigrationVersion
12
+
13
+ source_paths << File.join(File.dirname(__FILE__), "templates")
14
+
15
+ def create_migration_file
16
+ migration_template "migration_0.0.1.rb", "db/migrate/add_active_record_survey_node_map_group.rb"
17
+ end
18
+
19
+ def self.next_migration_number(dirname)
20
+ ::ActiveRecord::Generators::Base.next_migration_number dirname
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,6 @@
1
+ require 'rails/generators/base'
2
+ require 'active_record_survey/node_map_group/compatibility'
3
+
4
+ class ActiveRecordSurveyNodeMapGroupGenerator < Rails::Generators::Base
5
+ source_paths << File.join(File.dirname(__FILE__), 'templates')
6
+ end
@@ -0,0 +1,16 @@
1
+ module ActiveRecordSurvey
2
+ class NodeMapGroup < ActiveRecord::Base
3
+ module NextMigrationVersion
4
+ # while methods have moved around this has been the implementation
5
+ # since ActiveRecord 3.0
6
+ def next_migration_number(dirname)
7
+ next_migration_number = current_migration_number(dirname) + 1
8
+ if ActiveRecord::Base.timestamped_migrations
9
+ [Time.now.utc.strftime("%Y%m%d%H%M%S"), format("%.14d", next_migration_number)].max
10
+ else
11
+ format("%.3d", next_migration_number)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ class AddActiveRecordSurveyNodeMapGroup < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :active_record_survey_api_node_map_groups do |t|
4
+ t.references :active_record_survey
5
+
6
+ t.timestamps null: false
7
+ end
8
+
9
+ add_column :active_record_survey_node_maps, :active_record_survey_api_node_map_group_id, :integer
10
+ end
11
+
12
+ def self.down
13
+ drop_table :active_record_survey_node_map_groups
14
+ remove_column :active_record_survey_node_maps, :active_record_survey_api_node_map_group_id
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_record_survey-node_map_group
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Butch Marshall
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: active_record_survey
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.38
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.38
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: database_cleaner
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: factory_girl
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.11'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.11'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ description: Create groupings of ActiveRecordSurvey branching paths with ActiveRecordSurvey::NodeMapGroup
112
+ email:
113
+ - butch.a.marshall@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - README.md
123
+ - Rakefile
124
+ - active_record_survey-node_map_group.gemspec
125
+ - bin/console
126
+ - bin/setup
127
+ - lib/active_record_survey/node_map_group.rb
128
+ - lib/active_record_survey/node_map_group/class_methods.rb
129
+ - lib/active_record_survey/node_map_group/compatibility.rb
130
+ - lib/active_record_survey/node_map_group/instance_methods.rb
131
+ - lib/active_record_survey/node_map_group/version.rb
132
+ - lib/generators/active_record_survey/node_map_group/active_record_generator.rb
133
+ - lib/generators/active_record_survey/node_map_group/active_record_survey_node_map_group_generator.rb
134
+ - lib/generators/active_record_survey/node_map_group/next_migration_version.rb
135
+ - lib/generators/active_record_survey/node_map_group/templates/migration_0.0.1.rb
136
+ homepage: https://github.com/butchmarshall/active_record_survey-node_map_group
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.4.6
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: ActiveRecordSurvey NodeMap groups
160
+ test_files: []