od-surveys 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2a872c5833e4cb54b0c77646dca03711a8685ba3a725b0afd4d01bf8cdc8073
4
- data.tar.gz: b675fcbdbdbc9b4685ccc71fc218c3a9246361e8e613a8929ee25540172d9948
3
+ metadata.gz: 379cffea4fc0edd7bd3c527b3a5a93d1d58fda8ae095f5e1477fe35b845707fe
4
+ data.tar.gz: a902f66fb03d1b4381744da61e052d1513b3fff21398bb6270ca15af92fb59de
5
5
  SHA512:
6
- metadata.gz: 4395e80ca5974554e55a90637b9dfbd123939f90110248a973665c6cbf5bebc80d1ce7acd7a45cebef51b6b0c0d89aa99fcfc19b997c1b46b03caa11869d289a
7
- data.tar.gz: e630176fe323264ecf54a1e9ddfcfb7c43923eca2031f09429d24cf85a2a8cb4cc19a577f2bf095d6b79cd87be71ead10864411f57943f477875898ec069dbae
6
+ metadata.gz: 4a3b144bd106f17ab7425ec19880a21edd32f56cad389a309798bd7e62f54e1218920a618f0fb2e26f6f34e574a723beeafeed80981ce331a5d98fcf79f98bff
7
+ data.tar.gz: 50921b3f229fcf9243b17ec8236d97786500a58a46cc514976cf238bb02d757d42e86d41d5cd3064defe13c7d2daf98f3a20e09f8d6836e55a5db17d521ce685
data/README.md CHANGED
@@ -54,204 +54,8 @@ To use this gem run:
54
54
  ```ruby
55
55
  od-surveys models
56
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
57
  ```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
58
+ od-surveys migrations
255
59
  ```
256
60
 
257
61
  <br>
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Answer < ApplicationRecord
4
- has_paper_trail
4
+
5
5
  belongs_to :question
6
6
  belongs_to :survey_response
7
7
  has_many :answer_choices
@@ -1,5 +1,5 @@
1
1
  class AnswerChoice < ApplicationRecord
2
- has_paper_trail
2
+
3
3
  belongs_to :choice, optional: true
4
4
  belongs_to :answer
5
5
  end
@@ -1,5 +1,5 @@
1
1
  class Choice < ApplicationRecord
2
- has_paper_trail
2
+
3
3
  belongs_to :question
4
4
  has_many :answer_choices
5
5
  has_many :answers, through: :answer_choices
@@ -1,5 +1,5 @@
1
1
  class Question < ApplicationRecord
2
- has_paper_trail
2
+
3
3
  belongs_to :survey
4
4
  acts_as_list scope: :survey
5
5
  has_many :answers, dependent: :destroy
@@ -1,5 +1,5 @@
1
1
  class Survey < ApplicationRecord
2
- has_paper_trail
2
+
3
3
  has_many :platform_surveys, dependent: :destroy
4
4
  has_many :platform, through: :platform_surveys
5
5
  has_many :questions, dependent: :destroy
@@ -1,5 +1,5 @@
1
1
  class SurveyResponse < ApplicationRecord
2
- has_paper_trail
2
+
3
3
  belongs_to :survey
4
4
  # belongs_to :patient
5
5
  has_one :order
@@ -4,6 +4,11 @@ require 'thor'
4
4
  module ODSurveys
5
5
  class CLI < Thor
6
6
 
7
+ desc "migrations", "Generates migrations"
8
+ def migrations()
9
+ ODSurveys::Generators::Migrations.start([])
10
+ end
11
+
7
12
  desc "models", "Generates a models scaffold"
8
13
  def models()
9
14
  ODSurveys::Generators::Models.start([])
@@ -0,0 +1,20 @@
1
+ require 'thor/group'
2
+
3
+ module ODSurveys
4
+ module Generators
5
+ class Migrations < Thor::Group
6
+ include Thor::Actions
7
+
8
+ def self.source_root
9
+ File.dirname(__FILE__) + "/templates"
10
+ end
11
+ def copy_migrations
12
+ directory( File.dirname(__FILE__) + "/templates/migrate" , "./db/migrate")
13
+ run('rails db:create')
14
+ run('rails db:migrate')
15
+ end
16
+
17
+
18
+ end
19
+ end
20
+ end
@@ -9,10 +9,7 @@ module ODSurveys
9
9
  File.dirname(__FILE__) + "/templates"
10
10
  end
11
11
  def copy_models
12
- directory( File.dirname(__FILE__) + "/templates/migrate" , "./db/migrate")
13
12
  directory( File.dirname(__FILE__) + "/templates/models" , "./app/models")
14
- run('rails db:create')
15
- run('rails db:migrate')
16
13
  end
17
14
 
18
15
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Answer < ApplicationRecord
4
- has_paper_trail
4
+
5
5
  belongs_to :question
6
6
  belongs_to :survey_response
7
7
  has_many :answer_choices
@@ -1,5 +1,5 @@
1
1
  class AnswerChoice < ApplicationRecord
2
- has_paper_trail
2
+
3
3
  belongs_to :choice, optional: true
4
4
  belongs_to :answer
5
5
  end
@@ -1,5 +1,5 @@
1
1
  class Choice < ApplicationRecord
2
- has_paper_trail
2
+
3
3
  belongs_to :question
4
4
  has_many :answer_choices
5
5
  has_many :answers, through: :answer_choices
@@ -1,5 +1,5 @@
1
1
  class Question < ApplicationRecord
2
- has_paper_trail
2
+
3
3
  belongs_to :survey
4
4
  acts_as_list scope: :survey
5
5
  has_many :answers, dependent: :destroy
@@ -1,5 +1,5 @@
1
1
  class Survey < ApplicationRecord
2
- has_paper_trail
2
+
3
3
  has_many :platform_surveys, dependent: :destroy
4
4
  has_many :platform, through: :platform_surveys
5
5
  has_many :questions, dependent: :destroy
@@ -1,5 +1,5 @@
1
1
  class SurveyResponse < ApplicationRecord
2
- has_paper_trail
2
+
3
3
  belongs_to :survey
4
4
  # belongs_to :patient
5
5
  has_one :order
@@ -1,3 +1,3 @@
1
1
  module ODSurveys
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: od-surveys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Onward Web Development
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-06 00:00:00.000000000 Z
11
+ date: 2020-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -101,6 +101,7 @@ files:
101
101
  - db/migrate/20180611182929_create_answer_choices.rb
102
102
  - exe/od-surveys
103
103
  - lib/od/surveys/cli.rb
104
+ - lib/od/surveys/generators/migrations.rb
104
105
  - lib/od/surveys/generators/models.rb
105
106
  - lib/od/surveys/generators/templates/migrate/20180523221331_create_surveys.rb
106
107
  - lib/od/surveys/generators/templates/migrate/20180523221722_create_choices.rb