survey_constructor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +99 -0
- data/LICENSE.txt +21 -0
- data/README.md +281 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/surveyConstructor +3 -0
- data/lib/survey_constructor.rb +7 -0
- data/lib/survey_constructor/cli.rb +13 -0
- data/lib/survey_constructor/generators/models.rb +21 -0
- data/lib/survey_constructor/generators/templates/migrate/20180523221331_create_surveys.rb +10 -0
- data/lib/survey_constructor/generators/templates/migrate/20180523221722_create_choices.rb +9 -0
- data/lib/survey_constructor/generators/templates/migrate/20180523222506_create_questions.rb +11 -0
- data/lib/survey_constructor/generators/templates/migrate/20180523222646_create_answers.rb +9 -0
- data/lib/survey_constructor/generators/templates/migrate/20180608225714_create_survey_responses.rb +10 -0
- data/lib/survey_constructor/generators/templates/migrate/20180608230124_add_survey_respose_to_answer.rb +6 -0
- data/lib/survey_constructor/generators/templates/migrate/20180611182929_create_answer_choices.rb +10 -0
- data/lib/survey_constructor/generators/templates/models/answer.rb +25 -0
- data/lib/survey_constructor/generators/templates/models/answer_choice.rb +5 -0
- data/lib/survey_constructor/generators/templates/models/choice.rb +7 -0
- data/lib/survey_constructor/generators/templates/models/question.rb +17 -0
- data/lib/survey_constructor/generators/templates/models/survey.rb +10 -0
- data/lib/survey_constructor/generators/templates/models/survey_response.rb +9 -0
- data/lib/survey_constructor/version.rb +3 -0
- data/survey_constructor.gemspec +35 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a38861521bef6d2082dca684fe50eb50300345d1b60e65c03ce8dfb4ecbff53b
|
4
|
+
data.tar.gz: 35e1e06780f81f5176514f5e752e80ba192e5cc0e00e20f896388c151ee1783b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 739d3117c43d4ed6cec95e26202d45b2b339f7ae38096b66088ac6af6fcd5bded8ca8f827feaecc95509bfae6c5934616c585a15d6cf6f5fdc769192c9236c25
|
7
|
+
data.tar.gz: '0863b0cba69956144f94ec832a04964be4d7210bece80d37cf61ceb7f2bbb0abc7ee97c409993580360e928882e521d305a5c2e4dd8066546ec94f13091dc1c1'
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
data/Gemfile.lock
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
survey_constructor (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
|
+
rake (~> 12.0)
|
95
|
+
rspec (~> 3.9)
|
96
|
+
survey_constructor!
|
97
|
+
|
98
|
+
BUNDLED WITH
|
99
|
+
2.1.2
|
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -0,0 +1,281 @@
|
|
1
|
+
# SurveyConstructor
|
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 'survey_constructor'
|
39
|
+
```
|
40
|
+
|
41
|
+
And then execute:
|
42
|
+
|
43
|
+
$ bundle install
|
44
|
+
|
45
|
+
Or install it yourself as:
|
46
|
+
|
47
|
+
$ gem install survey_constructor
|
48
|
+
<br>
|
49
|
+
|
50
|
+
# Usage
|
51
|
+
|
52
|
+
To use this gem run:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
surveyConstructor 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/emrszon/survey_constructor. 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/emrszon/survey_constructor/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 SurveyConstructor project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/emrszon/survey_constructor/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "survey_constructor"
|
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__)
|
data/bin/setup
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'survey_constructor/generators/models'
|
2
|
+
require 'thor'
|
3
|
+
require 'survey_constructor'
|
4
|
+
module SurveyConstructor
|
5
|
+
class CLI < Thor
|
6
|
+
|
7
|
+
desc "models", "Generates a models scaffold"
|
8
|
+
def models()
|
9
|
+
SurveyConstructor::Generators::Models.start([])
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'thor/group'
|
2
|
+
|
3
|
+
module SurveyConstructor
|
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,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,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,35 @@
|
|
1
|
+
require_relative 'lib/survey_constructor/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "survey_constructor"
|
5
|
+
spec.version = SurveyConstructor::VERSION
|
6
|
+
spec.authors = ["Emerson Herrera Diaz"]
|
7
|
+
spec.email = ["emerson@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/emrszon/survey_constructor.git"
|
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/emrszon/survey_constructor.git"
|
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,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: survey_constructor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Emerson Herrera Diaz
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-04 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
|
+
- emerson@onwarddev.com
|
73
|
+
executables:
|
74
|
+
- surveyConstructor
|
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
|
+
- bin/console
|
88
|
+
- bin/setup
|
89
|
+
- exe/surveyConstructor
|
90
|
+
- lib/survey_constructor.rb
|
91
|
+
- lib/survey_constructor/cli.rb
|
92
|
+
- lib/survey_constructor/generators/models.rb
|
93
|
+
- lib/survey_constructor/generators/templates/migrate/20180523221331_create_surveys.rb
|
94
|
+
- lib/survey_constructor/generators/templates/migrate/20180523221722_create_choices.rb
|
95
|
+
- lib/survey_constructor/generators/templates/migrate/20180523222506_create_questions.rb
|
96
|
+
- lib/survey_constructor/generators/templates/migrate/20180523222646_create_answers.rb
|
97
|
+
- lib/survey_constructor/generators/templates/migrate/20180608225714_create_survey_responses.rb
|
98
|
+
- lib/survey_constructor/generators/templates/migrate/20180608230124_add_survey_respose_to_answer.rb
|
99
|
+
- lib/survey_constructor/generators/templates/migrate/20180611182929_create_answer_choices.rb
|
100
|
+
- lib/survey_constructor/generators/templates/models/answer.rb
|
101
|
+
- lib/survey_constructor/generators/templates/models/answer_choice.rb
|
102
|
+
- lib/survey_constructor/generators/templates/models/choice.rb
|
103
|
+
- lib/survey_constructor/generators/templates/models/question.rb
|
104
|
+
- lib/survey_constructor/generators/templates/models/survey.rb
|
105
|
+
- lib/survey_constructor/generators/templates/models/survey_response.rb
|
106
|
+
- lib/survey_constructor/version.rb
|
107
|
+
- survey_constructor.gemspec
|
108
|
+
homepage: https://github.com/emrszon/survey_constructor.git
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata:
|
112
|
+
homepage_uri: https://github.com/emrszon/survey_constructor.git
|
113
|
+
source_code_uri: https://github.com/emrszon/survey_constructor.git
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 2.3.0
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubygems_version: 3.1.2
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: This is a gem that allow generate survey models
|
133
|
+
test_files: []
|