od-surveys 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +6 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +6 -0
  7. data/Gemfile.lock +99 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +281 -0
  10. data/Rakefile +6 -0
  11. data/app/models/answer.rb +25 -0
  12. data/app/models/answer_choice.rb +5 -0
  13. data/app/models/choice.rb +7 -0
  14. data/app/models/question.rb +17 -0
  15. data/app/models/survey.rb +10 -0
  16. data/app/models/survey_response.rb +9 -0
  17. data/bin/console +14 -0
  18. data/bin/setup +8 -0
  19. data/db/migrate/20180523221331_create_surveys.rb +10 -0
  20. data/db/migrate/20180523221722_create_choices.rb +9 -0
  21. data/db/migrate/20180523222506_create_questions.rb +11 -0
  22. data/db/migrate/20180523222646_create_answers.rb +9 -0
  23. data/db/migrate/20180608225714_create_survey_responses.rb +10 -0
  24. data/db/migrate/20180608230124_add_survey_respose_to_answer.rb +6 -0
  25. data/db/migrate/20180611182929_create_answer_choices.rb +10 -0
  26. data/exe/ODSurveys +3 -0
  27. data/lib/od/surveys/cli.rb +13 -0
  28. data/lib/od/surveys/generators/models.rb +21 -0
  29. data/lib/od/surveys/generators/templates/migrate/20180523221331_create_surveys.rb +10 -0
  30. data/lib/od/surveys/generators/templates/migrate/20180523221722_create_choices.rb +9 -0
  31. data/lib/od/surveys/generators/templates/migrate/20180523222506_create_questions.rb +11 -0
  32. data/lib/od/surveys/generators/templates/migrate/20180523222646_create_answers.rb +9 -0
  33. data/lib/od/surveys/generators/templates/migrate/20180608225714_create_survey_responses.rb +10 -0
  34. data/lib/od/surveys/generators/templates/migrate/20180608230124_add_survey_respose_to_answer.rb +6 -0
  35. data/lib/od/surveys/generators/templates/migrate/20180611182929_create_answer_choices.rb +10 -0
  36. data/lib/od/surveys/generators/templates/models/answer.rb +25 -0
  37. data/lib/od/surveys/generators/templates/models/answer_choice.rb +5 -0
  38. data/lib/od/surveys/generators/templates/models/choice.rb +7 -0
  39. data/lib/od/surveys/generators/templates/models/question.rb +17 -0
  40. data/lib/od/surveys/generators/templates/models/survey.rb +10 -0
  41. data/lib/od/surveys/generators/templates/models/survey_response.rb +9 -0
  42. data/lib/od/surveys/surveys.rb +7 -0
  43. data/lib/od/surveys/version.rb +3 -0
  44. data/od-surveys.gemspec +35 -0
  45. metadata +146 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 27a09be32445aa299b9d8f8f1e3e52d3311913f8f21ee83af4f42cbcf2290f93
4
+ data.tar.gz: '091c3dc7c9730226857eda22a7198f6c0a4a9575acdf776f9fa78a7158bdcaf6'
5
+ SHA512:
6
+ metadata.gz: 69c3c1b0fe192cc8aa57a5128c78f52ab966e0a7bec2f6169c6cb9912cbbc6a654b99873d44d82a0a51b27a2286b0319eef247011cee7e9afa0b51aeae325c5b
7
+ data.tar.gz: 121f8e30ad364e7d6e294fa32e27c38d042b48b4ea8047fa5c480f59e8beff9bca09c2833df1abccbd75864c6ca59222cc8da7f92bd80dca409935ea5298f5a5
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at emerson@onwarddev.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in od-surveys.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
@@ -0,0 +1,99 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ od-surveys (0.1.0)
5
+ thor
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (6.0.3.2)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 0.7, < 2)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ zeitwerk (~> 2.2, >= 2.2.2)
16
+ aruba (1.0.2)
17
+ childprocess (>= 2.0, < 5.0)
18
+ contracts (~> 0.16.0)
19
+ cucumber (>= 2.4, < 5.0)
20
+ ffi (~> 1.9)
21
+ rspec-expectations (~> 3.4)
22
+ thor (~> 1.0)
23
+ builder (3.2.4)
24
+ childprocess (4.0.0)
25
+ concurrent-ruby (1.1.6)
26
+ contracts (0.16.0)
27
+ cucumber (4.0.0)
28
+ builder (~> 3.2, >= 3.2.3)
29
+ cucumber-core (~> 7.0, >= 7.0.0)
30
+ cucumber-cucumber-expressions (~> 10.1, >= 10.1.0)
31
+ cucumber-gherkin (~> 13.0, >= 13.0.0)
32
+ cucumber-html-formatter (~> 6.0, >= 6.0.1)
33
+ cucumber-messages (~> 12.1, >= 12.1.1)
34
+ cucumber-wire (~> 3.0, >= 3.0.0)
35
+ diff-lcs (~> 1.3, >= 1.3)
36
+ multi_test (~> 0.1, >= 0.1.2)
37
+ sys-uname (~> 1.0, >= 1.0.2)
38
+ cucumber-core (7.0.0)
39
+ cucumber-gherkin (~> 13.0, >= 13.0.0)
40
+ cucumber-messages (~> 12.1, >= 12.1.1)
41
+ cucumber-tag-expressions (~> 2.0, >= 2.0.4)
42
+ cucumber-cucumber-expressions (10.2.2)
43
+ cucumber-gherkin (13.0.0)
44
+ cucumber-messages (~> 12.0, >= 12.0.0)
45
+ cucumber-html-formatter (6.0.3)
46
+ cucumber-messages (~> 12.1, >= 12.1.1)
47
+ cucumber-messages (12.4.0)
48
+ protobuf-cucumber (~> 3.10, >= 3.10.8)
49
+ cucumber-tag-expressions (2.0.4)
50
+ cucumber-wire (3.0.0)
51
+ cucumber-core (~> 7.0, >= 7.0.0)
52
+ cucumber-cucumber-expressions (~> 10.1, >= 10.1.0)
53
+ cucumber-messages (~> 12.1, >= 12.1.1)
54
+ diff-lcs (1.4.4)
55
+ ffi (1.13.1)
56
+ i18n (1.8.5)
57
+ concurrent-ruby (~> 1.0)
58
+ middleware (0.1.0)
59
+ minitest (5.14.1)
60
+ multi_test (0.1.2)
61
+ protobuf-cucumber (3.10.8)
62
+ activesupport (>= 3.2)
63
+ middleware
64
+ thor
65
+ thread_safe
66
+ rake (12.3.3)
67
+ rspec (3.9.0)
68
+ rspec-core (~> 3.9.0)
69
+ rspec-expectations (~> 3.9.0)
70
+ rspec-mocks (~> 3.9.0)
71
+ rspec-core (3.9.2)
72
+ rspec-support (~> 3.9.3)
73
+ rspec-expectations (3.9.2)
74
+ diff-lcs (>= 1.2.0, < 2.0)
75
+ rspec-support (~> 3.9.0)
76
+ rspec-mocks (3.9.1)
77
+ diff-lcs (>= 1.2.0, < 2.0)
78
+ rspec-support (~> 3.9.0)
79
+ rspec-support (3.9.3)
80
+ sys-uname (1.2.1)
81
+ ffi (>= 1.0.0)
82
+ thor (1.0.1)
83
+ thread_safe (0.3.6)
84
+ tzinfo (1.2.7)
85
+ thread_safe (~> 0.1)
86
+ zeitwerk (2.4.0)
87
+
88
+ PLATFORMS
89
+ ruby
90
+
91
+ DEPENDENCIES
92
+ aruba
93
+ cucumber
94
+ od-surveys!
95
+ rake (~> 12.0)
96
+ rspec (~> 3.9)
97
+
98
+ BUNDLED WITH
99
+ 2.1.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Emerson Herrera Diaz
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,281 @@
1
+ # OD-Surveys
2
+
3
+ >**IMPORTANT MESSAGE:** Require pre-installation of rails
4
+
5
+ This is a gem that allow generate survey models using pre existing models. This models are
6
+ ```ruby
7
+ models
8
+ ├── answer_choice.rb
9
+ ├── answer.rb
10
+ ├── choice.rb
11
+ ├── question.rb
12
+ ├── survey.rb
13
+ └── survey_response.rb
14
+ ```
15
+ In addition, it allows generating and running the corresponding migrations:
16
+ ```ruby
17
+ db
18
+ └── migrate
19
+ ├── 20180523221331_create_surveys.rb
20
+ ├── 20180523221722_create_choices.rb
21
+ ├── 20180523222506_create_questions.rb
22
+ ├── 20180523222646_create_answers.rb
23
+ ├── 20180608225714_create_survey_responses.rb
24
+ ├── 20180608230124_add_survey_respose_to_answer.rb
25
+ └── 20180611182929_create_answer_choices.rb
26
+
27
+ ```
28
+ This files are copied to `"./app/models"` and `"./db/migrate"` respectively
29
+
30
+ <br>
31
+
32
+
33
+ # Installation
34
+
35
+ Add this line to your application's Gemfile:
36
+
37
+ ```ruby
38
+ gem 'od-surveys'
39
+ ```
40
+
41
+ And then execute:
42
+
43
+ $ bundle install
44
+
45
+ Or install it yourself as:
46
+
47
+ $ gem install od-surveys
48
+ <br>
49
+
50
+ # Usage
51
+
52
+ To use this gem run:
53
+
54
+ ```ruby
55
+ od-surveys models
56
+ ```
57
+
58
+ ## What do the generated files contain?
59
+
60
+ This files are directly generated to `"./app/models"` and `"./db/migrate"` respectively
61
+
62
+ ### **In the case of models:**
63
+
64
+
65
+ ```ruby
66
+ # answer_choice.rb
67
+
68
+ class AnswerChoice < ApplicationRecord
69
+ has_paper_trail
70
+ belongs_to :choice, optional: true
71
+ belongs_to :answer
72
+ end
73
+ ```
74
+ ```ruby
75
+ # answer.rb
76
+
77
+ class Answer < ApplicationRecord
78
+ has_paper_trail
79
+ belongs_to :question
80
+ belongs_to :survey_response
81
+ has_many :answer_choices
82
+ has_many :choices, through: :answer_choices
83
+ scope :ordered, -> { includes(:question).order('questions.position') }
84
+ accepts_nested_attributes_for :answer_choices, allow_destroy: true
85
+
86
+ def text_answer
87
+ return justification if question.text?
88
+
89
+ array_answers = choices.order(:id).map do |c|
90
+ placeholder = question.placeholder.blank? ? ', ' : ", #{question.placeholder} "
91
+ if c.justifiable
92
+ "#{c.value}#{placeholder}#{justification.capitalize}"
93
+ else
94
+ c.value
95
+ end
96
+ end
97
+ array_answers.join(', ')
98
+ end
99
+ end
100
+ ```
101
+ ```ruby
102
+ # choice.rb
103
+
104
+ class Choice < ApplicationRecord
105
+ has_paper_trail
106
+ belongs_to :question
107
+ has_many :answer_choices
108
+ has_many :answers, through: :answer_choices
109
+ validates_presence_of :value
110
+ end
111
+ ```
112
+ ```ruby
113
+ # question.rb
114
+
115
+ class Question < ApplicationRecord
116
+ has_paper_trail
117
+ belongs_to :survey
118
+ acts_as_list scope: :survey
119
+ has_many :answers, dependent: :destroy
120
+ has_many :choices, dependent: :destroy
121
+ validates_presence_of :title, :question_type
122
+ accepts_nested_attributes_for :choices, allow_destroy: true
123
+ enum question_type: %i[text multiple_choice unique_choice]
124
+ after_save :reorder_studios
125
+
126
+ private
127
+ def reorder_studios
128
+ self.insert_at(self.position) if self.position_changed?
129
+ end
130
+
131
+ end
132
+ ```
133
+ ```ruby
134
+ # survey.rb
135
+
136
+ class Survey < ApplicationRecord
137
+ has_paper_trail
138
+ has_many :platform_surveys, dependent: :destroy
139
+ has_many :platform, through: :platform_surveys
140
+ has_many :questions, dependent: :destroy
141
+ has_many :survey_responses, dependent: :destroy
142
+ has_many :patients#, through: :survey_responses
143
+ validates_presence_of :title, :description
144
+ accepts_nested_attributes_for :questions, allow_destroy: true
145
+ end
146
+ ```
147
+ ```ruby
148
+ # survey_response.rb
149
+
150
+ class SurveyResponse < ApplicationRecord
151
+ has_paper_trail
152
+ belongs_to :survey
153
+ # belongs_to :patient
154
+ has_one :order
155
+ has_many :answers, dependent: :destroy
156
+ accepts_nested_attributes_for :answers, allow_destroy: true
157
+
158
+ end
159
+ ```
160
+
161
+ ### **In the case of migrations:**
162
+
163
+ ```ruby
164
+ # 20180523221331_create_surveys.rb
165
+
166
+ class CreateSurveys < ActiveRecord::Migration[5.2]
167
+ def change
168
+ create_table :surveys do |t|
169
+ t.string :description
170
+ t.string :title
171
+
172
+ t.timestamps
173
+ end
174
+ end
175
+ end
176
+ ```
177
+ ```ruby
178
+ # 20180523221722_create_choices.rb
179
+
180
+ class CreateChoices < ActiveRecord::Migration[5.2]
181
+ def change
182
+ create_table :choices do |t|
183
+ t.string :value
184
+ t.belongs_to :question, index: true
185
+ t.timestamps
186
+ end
187
+ end
188
+ end
189
+ ```
190
+ ```ruby
191
+ # 20180523222506_create_questions.rb
192
+
193
+ class CreateQuestions < ActiveRecord::Migration[5.2]
194
+ def change
195
+ create_table :questions do |t|
196
+ t.string :title
197
+ t.integer :question_type
198
+ t.belongs_to :survey, index: true
199
+
200
+ t.timestamps
201
+ end
202
+ end
203
+ end
204
+ ```
205
+ ```ruby
206
+ # 20180523222646_create_answers.rb
207
+
208
+ class CreateAnswers < ActiveRecord::Migration[5.2]
209
+ def change
210
+ create_table :answers do |t|
211
+ t.string :justification
212
+ t.belongs_to :question, index: true
213
+ t.timestamps
214
+ end
215
+ end
216
+ end
217
+ ```
218
+ ```ruby
219
+ # 20180608225714_create_survey_responses.rb
220
+
221
+ class CreateSurveyResponses < ActiveRecord::Migration[5.2]
222
+ def change
223
+ create_table :survey_responses do |t|
224
+ t.belongs_to :survey, index: true
225
+ t.belongs_to :patient, index: true
226
+
227
+ t.timestamps
228
+ end
229
+ end
230
+ end
231
+ ```
232
+ ```ruby
233
+ # 20180608230124_add_survey_respose_to_answer.rb
234
+
235
+ class AddSurveyResposeToAnswer < ActiveRecord::Migration[5.2]
236
+ def change
237
+ add_column :answers, :survey_response_id, :integer
238
+ #Ex:- add_column("admin_users", "username", :string, :limit =>25, :after => "email")
239
+ end
240
+ end
241
+ ```
242
+ ```ruby
243
+ # 20180611182929_create_answer_choices.rb
244
+
245
+ class CreateAnswerChoices < ActiveRecord::Migration[5.2]
246
+ def change
247
+ create_table :answer_choices do |t|
248
+ t.belongs_to :answer, index: true
249
+ t.belongs_to :choice, index: true
250
+
251
+ t.timestamps
252
+ end
253
+ end
254
+ end
255
+ ```
256
+
257
+ <br>
258
+
259
+ # Development
260
+
261
+ 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.
262
+
263
+ 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).
264
+
265
+ <br>
266
+
267
+ # Contributing
268
+
269
+ Bug reports and pull requests are welcome on GitHub at https://github.com/onwarddev/od-surveys. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/onwarddev/od-surveys/blob/master/CODE_OF_CONDUCT.md).
270
+
271
+ <br>
272
+
273
+ # License
274
+
275
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
276
+
277
+ <br>
278
+
279
+ # Code of Conduct
280
+
281
+ Everyone interacting in the ODSurveys project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/onwarddev/od-surveys/blob/master/CODE_OF_CONDUCT.md).
@@ -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,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Answer < ApplicationRecord
4
+ has_paper_trail
5
+ belongs_to :question
6
+ belongs_to :survey_response
7
+ has_many :answer_choices
8
+ has_many :choices, through: :answer_choices
9
+ scope :ordered, -> { includes(:question).order('questions.position') }
10
+ accepts_nested_attributes_for :answer_choices, allow_destroy: true
11
+
12
+ def text_answer
13
+ return justification if question.text?
14
+
15
+ array_answers = choices.order(:id).map do |c|
16
+ placeholder = question.placeholder.blank? ? ', ' : ", #{question.placeholder} "
17
+ if c.justifiable
18
+ "#{c.value}#{placeholder}#{justification.capitalize}"
19
+ else
20
+ c.value
21
+ end
22
+ end
23
+ array_answers.join(', ')
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ class AnswerChoice < ApplicationRecord
2
+ has_paper_trail
3
+ belongs_to :choice, optional: true
4
+ belongs_to :answer
5
+ end
@@ -0,0 +1,7 @@
1
+ class Choice < ApplicationRecord
2
+ has_paper_trail
3
+ belongs_to :question
4
+ has_many :answer_choices
5
+ has_many :answers, through: :answer_choices
6
+ validates_presence_of :value
7
+ end
@@ -0,0 +1,17 @@
1
+ class Question < ApplicationRecord
2
+ has_paper_trail
3
+ belongs_to :survey
4
+ acts_as_list scope: :survey
5
+ has_many :answers, dependent: :destroy
6
+ has_many :choices, dependent: :destroy
7
+ validates_presence_of :title, :question_type
8
+ accepts_nested_attributes_for :choices, allow_destroy: true
9
+ enum question_type: %i[text multiple_choice unique_choice]
10
+ after_save :reorder_studios
11
+
12
+ private
13
+ def reorder_studios
14
+ self.insert_at(self.position) if self.position_changed?
15
+ end
16
+
17
+ end
@@ -0,0 +1,10 @@
1
+ class Survey < ApplicationRecord
2
+ has_paper_trail
3
+ has_many :platform_surveys, dependent: :destroy
4
+ has_many :platform, through: :platform_surveys
5
+ has_many :questions, dependent: :destroy
6
+ has_many :survey_responses, dependent: :destroy
7
+ has_many :patients#, through: :survey_responses
8
+ validates_presence_of :title, :description
9
+ accepts_nested_attributes_for :questions, allow_destroy: true
10
+ end
@@ -0,0 +1,9 @@
1
+ class SurveyResponse < ApplicationRecord
2
+ has_paper_trail
3
+ belongs_to :survey
4
+ # belongs_to :patient
5
+ has_one :order
6
+ has_many :answers, dependent: :destroy
7
+ accepts_nested_attributes_for :answers, allow_destroy: true
8
+
9
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "od/surveys"
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(__FILE__)
@@ -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,10 @@
1
+ class CreateSurveys < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :surveys do |t|
4
+ t.string :description
5
+ t.string :title
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ class CreateChoices < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :choices do |t|
4
+ t.string :value
5
+ t.belongs_to :question, index: true
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class CreateQuestions < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :questions do |t|
4
+ t.string :title
5
+ t.integer :question_type
6
+ t.belongs_to :survey, index: true
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ class CreateAnswers < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :answers do |t|
4
+ t.string :justification
5
+ t.belongs_to :question, index: true
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ class CreateSurveyResponses < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :survey_responses do |t|
4
+ t.belongs_to :survey, index: true
5
+ t.belongs_to :patient, index: true
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ class AddSurveyResposeToAnswer < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :answers, :survey_response_id, :integer
4
+ #Ex:- add_column("admin_users", "username", :string, :limit =>25, :after => "email")
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ class CreateAnswerChoices < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :answer_choices do |t|
4
+ t.belongs_to :answer, index: true
5
+ t.belongs_to :choice, index: true
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'od/surveys/cli'
3
+ ODSurveys::CLI.start
@@ -0,0 +1,13 @@
1
+ require 'od/surveys/generators/models'
2
+ require 'thor'
3
+
4
+ module ODSurveys
5
+ class CLI < Thor
6
+
7
+ desc "models", "Generates a models scaffold"
8
+ def models()
9
+ ODSurveys::Generators::Models.start([])
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ require 'thor/group'
2
+
3
+ module ODSurveys
4
+ module Generators
5
+ class Models < Thor::Group
6
+ include Thor::Actions
7
+
8
+ def self.source_root
9
+ File.dirname(__FILE__) + "/templates"
10
+ end
11
+ def copy_models
12
+ directory( File.dirname(__FILE__) + "/templates/migrate" , "./db/migrate")
13
+ directory( File.dirname(__FILE__) + "/templates/models" , "./app/models")
14
+ run('rails db:create')
15
+ run('rails db:migrate')
16
+ end
17
+
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ class CreateSurveys < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :surveys do |t|
4
+ t.string :description
5
+ t.string :title
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ class CreateChoices < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :choices do |t|
4
+ t.string :value
5
+ t.belongs_to :question, index: true
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class CreateQuestions < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :questions do |t|
4
+ t.string :title
5
+ t.integer :question_type
6
+ t.belongs_to :survey, index: true
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ class CreateAnswers < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :answers do |t|
4
+ t.string :justification
5
+ t.belongs_to :question, index: true
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ class CreateSurveyResponses < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :survey_responses do |t|
4
+ t.belongs_to :survey, index: true
5
+ t.belongs_to :patient, index: true
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ class AddSurveyResposeToAnswer < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :answers, :survey_response_id, :integer
4
+ #Ex:- add_column("admin_users", "username", :string, :limit =>25, :after => "email")
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ class CreateAnswerChoices < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :answer_choices do |t|
4
+ t.belongs_to :answer, index: true
5
+ t.belongs_to :choice, index: true
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Answer < ApplicationRecord
4
+ has_paper_trail
5
+ belongs_to :question
6
+ belongs_to :survey_response
7
+ has_many :answer_choices
8
+ has_many :choices, through: :answer_choices
9
+ scope :ordered, -> { includes(:question).order('questions.position') }
10
+ accepts_nested_attributes_for :answer_choices, allow_destroy: true
11
+
12
+ def text_answer
13
+ return justification if question.text?
14
+
15
+ array_answers = choices.order(:id).map do |c|
16
+ placeholder = question.placeholder.blank? ? ', ' : ", #{question.placeholder} "
17
+ if c.justifiable
18
+ "#{c.value}#{placeholder}#{justification.capitalize}"
19
+ else
20
+ c.value
21
+ end
22
+ end
23
+ array_answers.join(', ')
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ class AnswerChoice < ApplicationRecord
2
+ has_paper_trail
3
+ belongs_to :choice, optional: true
4
+ belongs_to :answer
5
+ end
@@ -0,0 +1,7 @@
1
+ class Choice < ApplicationRecord
2
+ has_paper_trail
3
+ belongs_to :question
4
+ has_many :answer_choices
5
+ has_many :answers, through: :answer_choices
6
+ validates_presence_of :value
7
+ end
@@ -0,0 +1,17 @@
1
+ class Question < ApplicationRecord
2
+ has_paper_trail
3
+ belongs_to :survey
4
+ acts_as_list scope: :survey
5
+ has_many :answers, dependent: :destroy
6
+ has_many :choices, dependent: :destroy
7
+ validates_presence_of :title, :question_type
8
+ accepts_nested_attributes_for :choices, allow_destroy: true
9
+ enum question_type: %i[text multiple_choice unique_choice]
10
+ after_save :reorder_studios
11
+
12
+ private
13
+ def reorder_studios
14
+ self.insert_at(self.position) if self.position_changed?
15
+ end
16
+
17
+ end
@@ -0,0 +1,10 @@
1
+ class Survey < ApplicationRecord
2
+ has_paper_trail
3
+ has_many :platform_surveys, dependent: :destroy
4
+ has_many :platform, through: :platform_surveys
5
+ has_many :questions, dependent: :destroy
6
+ has_many :survey_responses, dependent: :destroy
7
+ has_many :patients#, through: :survey_responses
8
+ validates_presence_of :title, :description
9
+ accepts_nested_attributes_for :questions, allow_destroy: true
10
+ end
@@ -0,0 +1,9 @@
1
+ class SurveyResponse < ApplicationRecord
2
+ has_paper_trail
3
+ belongs_to :survey
4
+ # belongs_to :patient
5
+ has_one :order
6
+ has_many :answers, dependent: :destroy
7
+ accepts_nested_attributes_for :answers, allow_destroy: true
8
+
9
+ end
@@ -0,0 +1,7 @@
1
+ require "od/surveys/version"
2
+
3
+ module ODSurveys
4
+ class Error < StandardError; end
5
+
6
+
7
+ end
@@ -0,0 +1,3 @@
1
+ module ODSurveys
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,35 @@
1
+ require_relative 'lib/od/surveys/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "od-surveys"
5
+ spec.version = ODSurveys::VERSION
6
+ spec.authors ='Onward Web Development'
7
+ spec.email = ['hello@onwarddev.com']
8
+
9
+ spec.summary = "This is a gem that allow generate survey models"
10
+ spec.description = "This is a gem that allow generate survey models using pre existing models. In addition, it allows generating and running the corresponding migrations"
11
+ spec.homepage = "https://github.com/onwarddev/od-surveys"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ #spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/onwarddev/od-surveys"
19
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ # Dependencies
30
+ spec.add_dependency "thor"
31
+ # Development dependencies
32
+ spec.add_development_dependency "rspec", "~> 3.9"
33
+ spec.add_development_dependency "cucumber"
34
+ spec.add_development_dependency "aruba"
35
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: od-surveys
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Onward Web Development
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-08-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: cucumber
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: aruba
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: This is a gem that allow generate survey models using pre existing models.
70
+ In addition, it allows generating and running the corresponding migrations
71
+ email:
72
+ - hello@onwarddev.com
73
+ executables:
74
+ - ODSurveys
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - app/models/answer.rb
88
+ - app/models/answer_choice.rb
89
+ - app/models/choice.rb
90
+ - app/models/question.rb
91
+ - app/models/survey.rb
92
+ - app/models/survey_response.rb
93
+ - bin/console
94
+ - bin/setup
95
+ - db/migrate/20180523221331_create_surveys.rb
96
+ - db/migrate/20180523221722_create_choices.rb
97
+ - db/migrate/20180523222506_create_questions.rb
98
+ - db/migrate/20180523222646_create_answers.rb
99
+ - db/migrate/20180608225714_create_survey_responses.rb
100
+ - db/migrate/20180608230124_add_survey_respose_to_answer.rb
101
+ - db/migrate/20180611182929_create_answer_choices.rb
102
+ - exe/ODSurveys
103
+ - lib/od/surveys/cli.rb
104
+ - lib/od/surveys/generators/models.rb
105
+ - lib/od/surveys/generators/templates/migrate/20180523221331_create_surveys.rb
106
+ - lib/od/surveys/generators/templates/migrate/20180523221722_create_choices.rb
107
+ - lib/od/surveys/generators/templates/migrate/20180523222506_create_questions.rb
108
+ - lib/od/surveys/generators/templates/migrate/20180523222646_create_answers.rb
109
+ - lib/od/surveys/generators/templates/migrate/20180608225714_create_survey_responses.rb
110
+ - lib/od/surveys/generators/templates/migrate/20180608230124_add_survey_respose_to_answer.rb
111
+ - lib/od/surveys/generators/templates/migrate/20180611182929_create_answer_choices.rb
112
+ - lib/od/surveys/generators/templates/models/answer.rb
113
+ - lib/od/surveys/generators/templates/models/answer_choice.rb
114
+ - lib/od/surveys/generators/templates/models/choice.rb
115
+ - lib/od/surveys/generators/templates/models/question.rb
116
+ - lib/od/surveys/generators/templates/models/survey.rb
117
+ - lib/od/surveys/generators/templates/models/survey_response.rb
118
+ - lib/od/surveys/surveys.rb
119
+ - lib/od/surveys/version.rb
120
+ - od-surveys.gemspec
121
+ homepage: https://github.com/onwarddev/od-surveys
122
+ licenses:
123
+ - MIT
124
+ metadata:
125
+ homepage_uri: https://github.com/onwarddev/od-surveys
126
+ source_code_uri: https://github.com/onwarddev/od-surveys
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: 2.3.0
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubygems_version: 3.1.2
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: This is a gem that allow generate survey models
146
+ test_files: []