surveyable 0.1.10

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8beeb46bb2d89cc7d1255f6606a372af2c7883eb
4
+ data.tar.gz: c4244d7c4446a7f51082563de0a26d895e1a8e34
5
+ SHA512:
6
+ metadata.gz: 6b66deba70961e6a2e53a5633a5192917ee28750441377c4b4172bfcd661f31a589865d841a952ab9d59f26bb62c36d3da162205a42487c4ced7915d0a381103
7
+ data.tar.gz: 639e7cee5ef9c8e4d416203f5655aee7969791646039fb2989a9021cfc369d16ff4d32d626fb1d77bbed42b601f3b4ac3c628deeaae5feff7ae4a345cc2f39ad
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in surveyable.gemspec
4
+ gemspec
5
+ gem 'rake'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Global Impact
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,57 @@
1
+ # Surveyable
2
+
3
+ Simple gem to deal with attaching 'surveys' to existing models. This involves question and answer types defined here.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'surveyable'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install surveyable
20
+
21
+ ## Usage
22
+
23
+ Run migrations (to be included as files soon)
24
+
25
+ ### Migrations
26
+
27
+ create_table :questions do |t|
28
+ t.integer :survey_id
29
+ t.string :survey_type
30
+ t.text :text
31
+ t.string :type
32
+ t.boolean :required
33
+ end
34
+ create_table :answers do |t|
35
+ t.integer :question_id
36
+ t.integer :response_id
37
+ t.string :response_type
38
+ t.text :text
39
+ t.integer :answer_choice_id
40
+ t.index [:response_id,:response_type]
41
+ end
42
+ create_table :answer_choices do |t|
43
+ t.integer :question_id
44
+ t.text :text
45
+ t.index :question_id
46
+ end
47
+
48
+ ### Attach to models
49
+ Put 'acts_as_survey' in your survey class (the model that needs custom questions).
50
+ Put 'acts_as_response' in your response class (the model that your answers will attach to).
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/globalimpact/surveyable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
54
+
55
+ ##License
56
+
57
+ MIT License. Copyright 2015 Global Impact. https://charity.org
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "surveyable"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,18 @@
1
+ require "surveyable/version"
2
+
3
+
4
+
5
+ module Surveyable
6
+ # Your code goes here...
7
+ end
8
+ require "surveyable/acts_as_survey"
9
+ require "surveyable/acts_as_response"
10
+ require "surveyable/answer"
11
+ require "surveyable/answer_choice"
12
+ require 'surveyable/question'
13
+
14
+ ActiveSupport.on_load(:active_record) do
15
+ include Surveyable::ActsAsSurvey
16
+ include Surveyable::ActsAsResponse
17
+
18
+ end
@@ -0,0 +1,20 @@
1
+ module Surveyable
2
+ module ActsAsResponse
3
+ def self.included(base)
4
+ base.send :extend, ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ def acts_as_response(options = {})
9
+ has_many :answers, as: :response, class_name: 'Surveyable::Answer'
10
+ accepts_nested_attributes_for :answers
11
+ send :include, InstanceMethods
12
+ end
13
+ end
14
+ module InstanceMethods
15
+ def survey
16
+ nil
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ module Surveyable
2
+ module ActsAsSurvey
3
+ def self.included(base)
4
+ base.send :extend, ClassMethods
5
+ end
6
+ module ClassMethods
7
+ def acts_as_survey(options = {})
8
+ has_many :questions, as: :survey, class_name: 'Surveyable::Question'
9
+ send :include, InstanceMethods
10
+ end
11
+ end
12
+ module InstanceMethods
13
+ def responses
14
+ []
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ module Surveyable
2
+ class Answer < ActiveRecord::Base
3
+ belongs_to :response, polymorphic: true
4
+ belongs_to :question
5
+ belongs_to :answer_choice
6
+
7
+ scope :required, -> {joins(:question).where('questions.required'=>true)}
8
+ scope :answered, -> {where("(answers.text IS NOT NULL AND answers.text <> '') OR answers.answer_choice_id IS NOT NULL")}
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ module Surveyable
2
+ class AnswerChoice < ActiveRecord::Base
3
+ belongs_to :question
4
+ has_one :answer
5
+ end
6
+ end
@@ -0,0 +1,99 @@
1
+ module Surveyable
2
+ class Question < ActiveRecord::Base
3
+ belongs_to :survey, polymorphic: true
4
+ has_many :answers, :dependent => :restrict_with_error
5
+ has_many :answer_choices, dependent: :destroy
6
+ STI_TYPES = %w[InfoField HiddenField BooleanField DateField SingleSelectField MultiSelectField TextField StringField IntegerField MoneyAmountField SingleDocumentField MultiDocumentField TelephoneField RelationshipSelectField]
7
+ accepts_nested_attributes_for :answer_choices, :allow_destroy => true,
8
+ :reject_if => lambda { |a| a[:text].blank? }
9
+ validates_presence_of :text
10
+ validates_presence_of :type
11
+
12
+ scope :required, -> { where(required:true)}
13
+ def field_type
14
+ 'text'
15
+ end
16
+ end
17
+ class InfoField < Question
18
+ def field_type
19
+ 'noAnswer'
20
+ end
21
+ end
22
+
23
+
24
+ class HiddenField < Question
25
+ def field_type
26
+ 'hidden'
27
+ end
28
+ end
29
+
30
+ class BooleanField < Question
31
+ def field_type
32
+ 'boolean'
33
+ end
34
+ end
35
+
36
+ class DateField < Question
37
+ def field_type
38
+ 'date'
39
+ end
40
+ end
41
+
42
+ class SingleSelectField < Question
43
+ def field_type
44
+ 'select'
45
+ end
46
+ end
47
+
48
+ class RelationshipSelectField < SingleSelectField
49
+
50
+ end
51
+
52
+ class MultiSelectField < Question
53
+ def field_type
54
+ 'select'
55
+ end
56
+ end
57
+
58
+ class TextField < Question
59
+ def field_type
60
+ 'textarea'
61
+ end
62
+ end
63
+
64
+ class StringField < Question
65
+ def field_type
66
+ 'text'
67
+ end
68
+ end
69
+
70
+ class IntegerField < Question
71
+ def field_type
72
+ 'number'
73
+ end
74
+ end
75
+
76
+ class MoneyAmountField < Question
77
+ def field_type
78
+ 'text'
79
+ end
80
+ end
81
+
82
+ class SingleDocumentField < Question
83
+ def field_type
84
+ 'file'
85
+ end
86
+ end
87
+
88
+ class MultiDocumentField < Question
89
+ def field_type
90
+ 'file'
91
+ end
92
+ end
93
+
94
+ class TelephoneField < Question
95
+ def field_type
96
+ 'tel'
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,3 @@
1
+ module Surveyable
2
+ VERSION = "0.1.10"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'surveyable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "surveyable"
8
+ spec.version = Surveyable::VERSION
9
+ spec.authors = ["Lee Dykes"]
10
+ spec.email = ['lee.dykes@charity.org']
11
+
12
+ spec.summary = 'Models for attaching questions to a survey (polymorphic) and answers to a response (polymorphic)'
13
+ spec.description = 'Models for attaching questions to a survey (polymorphic) and answers to a response (polymorphic)'
14
+ spec.homepage = 'https://github.com/globalimpact/surveyable'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ #spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_runtime_dependency "activerecord", "~> 4.0", '>=4.0.0'
25
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: surveyable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.10
5
+ platform: ruby
6
+ authors:
7
+ - Lee Dykes
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 4.0.0
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '4.0'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 4.0.0
47
+ description: Models for attaching questions to a survey (polymorphic) and answers
48
+ to a response (polymorphic)
49
+ email:
50
+ - lee.dykes@charity.org
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - ".gitignore"
56
+ - CODE_OF_CONDUCT.md
57
+ - Gemfile
58
+ - MIT-LICENSE
59
+ - README.md
60
+ - Rakefile
61
+ - bin/console
62
+ - bin/setup
63
+ - lib/surveyable.rb
64
+ - lib/surveyable/acts_as_response.rb
65
+ - lib/surveyable/acts_as_survey.rb
66
+ - lib/surveyable/answer.rb
67
+ - lib/surveyable/answer_choice.rb
68
+ - lib/surveyable/question.rb
69
+ - lib/surveyable/version.rb
70
+ - surveyable.gemspec
71
+ homepage: https://github.com/globalimpact/surveyable
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.2.2
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Models for attaching questions to a survey (polymorphic) and answers to a
95
+ response (polymorphic)
96
+ test_files: []