quby-mongoid 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "quby", :git=>"git@github.com:roqua/quby_engine.git", :ref=>"1a6ee38bb2499fd9938dbdb4bf8e8033920f6659"
6
+ gem "appraisal", "1.0.0.beta3"
7
+ gem "mongoid", "~> 3.0"
8
+
9
+ gemspec :path=>".././"
@@ -0,0 +1,207 @@
1
+ GIT
2
+ remote: git@github.com:roqua/quby_engine.git
3
+ revision: 1a6ee38bb2499fd9938dbdb4bf8e8033920f6659
4
+ ref: 1a6ee38bb2499fd9938dbdb4bf8e8033920f6659
5
+ specs:
6
+ quby (1.0.0)
7
+ addressable
8
+ coffee-rails
9
+ compass-rails
10
+ haml
11
+ jquery-rails (~> 2.2.1)
12
+ json
13
+ maruku (= 0.6.1)
14
+ opencpu (~> 0.6.0)
15
+ rails (>= 3.2, < 5.0)
16
+ ryansch-andand
17
+ sass-rails (>= 3.2, < 5.0)
18
+ susy (~> 1.0.rc)
19
+ virtus (~> 1.0)
20
+
21
+ PATH
22
+ remote: .././
23
+ specs:
24
+ quby-mongoid (0.0.1)
25
+ mongoid (>= 2.2, < 5.0)
26
+ quby
27
+
28
+ GEM
29
+ remote: https://rubygems.org/
30
+ specs:
31
+ actionmailer (3.2.18)
32
+ actionpack (= 3.2.18)
33
+ mail (~> 2.5.4)
34
+ actionpack (3.2.18)
35
+ activemodel (= 3.2.18)
36
+ activesupport (= 3.2.18)
37
+ builder (~> 3.0.0)
38
+ erubis (~> 2.7.0)
39
+ journey (~> 1.0.4)
40
+ rack (~> 1.4.5)
41
+ rack-cache (~> 1.2)
42
+ rack-test (~> 0.6.1)
43
+ sprockets (~> 2.2.1)
44
+ activemodel (3.2.18)
45
+ activesupport (= 3.2.18)
46
+ builder (~> 3.0.0)
47
+ activerecord (3.2.18)
48
+ activemodel (= 3.2.18)
49
+ activesupport (= 3.2.18)
50
+ arel (~> 3.0.2)
51
+ tzinfo (~> 0.3.29)
52
+ activeresource (3.2.18)
53
+ activemodel (= 3.2.18)
54
+ activesupport (= 3.2.18)
55
+ activesupport (3.2.18)
56
+ i18n (~> 0.6, >= 0.6.4)
57
+ multi_json (~> 1.0)
58
+ addressable (2.3.6)
59
+ appraisal (1.0.0.beta3)
60
+ bundler
61
+ rake
62
+ thor (>= 0.14.0)
63
+ arel (3.0.3)
64
+ axiom-types (0.1.1)
65
+ descendants_tracker (~> 0.0.4)
66
+ ice_nine (~> 0.11.0)
67
+ thread_safe (~> 0.3, >= 0.3.1)
68
+ builder (3.0.4)
69
+ chunky_png (1.3.1)
70
+ coderay (1.1.0)
71
+ coercible (1.0.0)
72
+ descendants_tracker (~> 0.0.1)
73
+ coffee-rails (3.2.1)
74
+ coffee-script (>= 2.2.0)
75
+ railties (~> 3.2.0.beta)
76
+ coffee-script (2.2.0)
77
+ coffee-script-source
78
+ execjs
79
+ coffee-script-source (1.7.0)
80
+ compass (0.12.6)
81
+ chunky_png (~> 1.2)
82
+ fssm (>= 0.2.7)
83
+ sass (~> 3.2.19)
84
+ compass-rails (1.1.7)
85
+ compass (>= 0.12.2)
86
+ sprockets (<= 2.11.0)
87
+ database_cleaner (1.2.0)
88
+ descendants_tracker (0.0.4)
89
+ thread_safe (~> 0.3, >= 0.3.1)
90
+ diff-lcs (1.2.5)
91
+ equalizer (0.0.9)
92
+ erubis (2.7.0)
93
+ execjs (2.2.0)
94
+ fssm (0.2.10)
95
+ haml (4.0.5)
96
+ tilt
97
+ hike (1.2.3)
98
+ httparty (0.13.1)
99
+ json (~> 1.8)
100
+ multi_xml (>= 0.5.2)
101
+ i18n (0.6.9)
102
+ ice_nine (0.11.0)
103
+ journey (1.0.4)
104
+ jquery-rails (2.2.2)
105
+ railties (>= 3.0, < 5.0)
106
+ thor (>= 0.14, < 2.0)
107
+ json (1.8.1)
108
+ mail (2.5.4)
109
+ mime-types (~> 1.16)
110
+ treetop (~> 1.4.8)
111
+ maruku (0.6.1)
112
+ syntax (>= 1.0.0)
113
+ method_source (0.8.2)
114
+ mime-types (1.25.1)
115
+ mongoid (3.1.6)
116
+ activemodel (~> 3.2)
117
+ moped (~> 1.4)
118
+ origin (~> 1.0)
119
+ tzinfo (~> 0.3.29)
120
+ moped (1.5.2)
121
+ multi_json (1.10.1)
122
+ multi_xml (0.5.5)
123
+ opencpu (0.6.2)
124
+ httparty (~> 0.13, >= 0.13.1)
125
+ yajl-ruby (~> 1.2, >= 1.2.0)
126
+ origin (1.1.0)
127
+ polyglot (0.3.5)
128
+ pry (0.10.0)
129
+ coderay (~> 1.1.0)
130
+ method_source (~> 0.8.1)
131
+ slop (~> 3.4)
132
+ rack (1.4.5)
133
+ rack-cache (1.2)
134
+ rack (>= 0.4)
135
+ rack-ssl (1.3.4)
136
+ rack
137
+ rack-test (0.6.2)
138
+ rack (>= 1.0)
139
+ rails (3.2.18)
140
+ actionmailer (= 3.2.18)
141
+ actionpack (= 3.2.18)
142
+ activerecord (= 3.2.18)
143
+ activeresource (= 3.2.18)
144
+ activesupport (= 3.2.18)
145
+ bundler (~> 1.0)
146
+ railties (= 3.2.18)
147
+ railties (3.2.18)
148
+ actionpack (= 3.2.18)
149
+ activesupport (= 3.2.18)
150
+ rack-ssl (~> 1.3.2)
151
+ rake (>= 0.8.7)
152
+ rdoc (~> 3.4)
153
+ thor (>= 0.14.6, < 2.0)
154
+ rake (10.3.2)
155
+ rdoc (3.12.2)
156
+ json (~> 1.4)
157
+ rspec (2.14.1)
158
+ rspec-core (~> 2.14.0)
159
+ rspec-expectations (~> 2.14.0)
160
+ rspec-mocks (~> 2.14.0)
161
+ rspec-core (2.14.8)
162
+ rspec-expectations (2.14.5)
163
+ diff-lcs (>= 1.1.3, < 2.0)
164
+ rspec-mocks (2.14.6)
165
+ ryansch-andand (1.3.2)
166
+ sass (3.2.19)
167
+ sass-rails (3.2.6)
168
+ railties (~> 3.2.0)
169
+ sass (>= 3.1.10)
170
+ tilt (~> 1.3)
171
+ slop (3.5.0)
172
+ sprockets (2.2.2)
173
+ hike (~> 1.2)
174
+ multi_json (~> 1.0)
175
+ rack (~> 1.0)
176
+ tilt (~> 1.1, != 1.3.0)
177
+ susy (1.0.9)
178
+ compass (>= 0.12.2)
179
+ sass (>= 3.2.0)
180
+ syntax (1.2.0)
181
+ thor (0.19.1)
182
+ thread_safe (0.3.4)
183
+ tilt (1.4.1)
184
+ treetop (1.4.15)
185
+ polyglot
186
+ polyglot (>= 0.3.1)
187
+ tzinfo (0.3.39)
188
+ virtus (1.0.2)
189
+ axiom-types (~> 0.1)
190
+ coercible (~> 1.0)
191
+ descendants_tracker (~> 0.0.3)
192
+ equalizer (~> 0.0.9)
193
+ yajl-ruby (1.2.1)
194
+
195
+ PLATFORMS
196
+ ruby
197
+
198
+ DEPENDENCIES
199
+ appraisal (= 1.0.0.beta3)
200
+ bundler (~> 1.6)
201
+ database_cleaner
202
+ mongoid (~> 3.0)
203
+ pry
204
+ quby!
205
+ quby-mongoid!
206
+ rake
207
+ rspec (~> 2.14.0)
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "quby", :git=>"git@github.com:roqua/quby_engine.git", :ref=>"1a6ee38bb2499fd9938dbdb4bf8e8033920f6659"
6
+ gem "appraisal", "1.0.0.beta3"
7
+ gem "mongoid", "~> 4.0.0.beta1"
8
+
9
+ gemspec :path=>".././"
@@ -0,0 +1,212 @@
1
+ GIT
2
+ remote: git@github.com:roqua/quby_engine.git
3
+ revision: 1a6ee38bb2499fd9938dbdb4bf8e8033920f6659
4
+ ref: 1a6ee38bb2499fd9938dbdb4bf8e8033920f6659
5
+ specs:
6
+ quby (1.0.0)
7
+ addressable
8
+ coffee-rails
9
+ compass-rails
10
+ haml
11
+ jquery-rails (~> 2.2.1)
12
+ json
13
+ maruku (= 0.6.1)
14
+ opencpu (~> 0.6.0)
15
+ rails (>= 3.2, < 5.0)
16
+ ryansch-andand
17
+ sass-rails (>= 3.2, < 5.0)
18
+ susy (~> 1.0.rc)
19
+ virtus (~> 1.0)
20
+
21
+ PATH
22
+ remote: .././
23
+ specs:
24
+ quby-mongoid (0.0.1)
25
+ mongoid (>= 2.2, < 5.0)
26
+ quby
27
+
28
+ GEM
29
+ remote: https://rubygems.org/
30
+ specs:
31
+ actionmailer (4.1.1)
32
+ actionpack (= 4.1.1)
33
+ actionview (= 4.1.1)
34
+ mail (~> 2.5.4)
35
+ actionpack (4.1.1)
36
+ actionview (= 4.1.1)
37
+ activesupport (= 4.1.1)
38
+ rack (~> 1.5.2)
39
+ rack-test (~> 0.6.2)
40
+ actionview (4.1.1)
41
+ activesupport (= 4.1.1)
42
+ builder (~> 3.1)
43
+ erubis (~> 2.7.0)
44
+ activemodel (4.1.1)
45
+ activesupport (= 4.1.1)
46
+ builder (~> 3.1)
47
+ activerecord (4.1.1)
48
+ activemodel (= 4.1.1)
49
+ activesupport (= 4.1.1)
50
+ arel (~> 5.0.0)
51
+ activesupport (4.1.1)
52
+ i18n (~> 0.6, >= 0.6.9)
53
+ json (~> 1.7, >= 1.7.7)
54
+ minitest (~> 5.1)
55
+ thread_safe (~> 0.1)
56
+ tzinfo (~> 1.1)
57
+ addressable (2.3.6)
58
+ appraisal (1.0.0.beta3)
59
+ bundler
60
+ rake
61
+ thor (>= 0.14.0)
62
+ arel (5.0.1.20140414130214)
63
+ axiom-types (0.1.1)
64
+ descendants_tracker (~> 0.0.4)
65
+ ice_nine (~> 0.11.0)
66
+ thread_safe (~> 0.3, >= 0.3.1)
67
+ bson (2.3.0)
68
+ builder (3.2.2)
69
+ chunky_png (1.3.1)
70
+ coderay (1.1.0)
71
+ coercible (1.0.0)
72
+ descendants_tracker (~> 0.0.1)
73
+ coffee-rails (4.0.1)
74
+ coffee-script (>= 2.2.0)
75
+ railties (>= 4.0.0, < 5.0)
76
+ coffee-script (2.2.0)
77
+ coffee-script-source
78
+ execjs
79
+ coffee-script-source (1.7.0)
80
+ compass (0.12.6)
81
+ chunky_png (~> 1.2)
82
+ fssm (>= 0.2.7)
83
+ sass (~> 3.2.19)
84
+ compass-rails (1.1.7)
85
+ compass (>= 0.12.2)
86
+ sprockets (<= 2.11.0)
87
+ connection_pool (2.0.0)
88
+ database_cleaner (1.2.0)
89
+ descendants_tracker (0.0.4)
90
+ thread_safe (~> 0.3, >= 0.3.1)
91
+ diff-lcs (1.2.5)
92
+ equalizer (0.0.9)
93
+ erubis (2.7.0)
94
+ execjs (2.2.0)
95
+ fssm (0.2.10)
96
+ haml (4.0.5)
97
+ tilt
98
+ hike (1.2.3)
99
+ httparty (0.13.1)
100
+ json (~> 1.8)
101
+ multi_xml (>= 0.5.2)
102
+ i18n (0.6.9)
103
+ ice_nine (0.11.0)
104
+ jquery-rails (2.2.2)
105
+ railties (>= 3.0, < 5.0)
106
+ thor (>= 0.14, < 2.0)
107
+ json (1.8.1)
108
+ mail (2.5.4)
109
+ mime-types (~> 1.16)
110
+ treetop (~> 1.4.8)
111
+ maruku (0.6.1)
112
+ syntax (>= 1.0.0)
113
+ method_source (0.8.2)
114
+ mime-types (1.25.1)
115
+ minitest (5.3.5)
116
+ mongoid (4.0.0)
117
+ activemodel (~> 4.0)
118
+ moped (~> 2.0.0)
119
+ origin (~> 2.1)
120
+ tzinfo (>= 0.3.37)
121
+ moped (2.0.0)
122
+ bson (~> 2.2)
123
+ connection_pool (~> 2.0)
124
+ optionable (~> 0.2.0)
125
+ multi_json (1.10.1)
126
+ multi_xml (0.5.5)
127
+ opencpu (0.6.2)
128
+ httparty (~> 0.13, >= 0.13.1)
129
+ yajl-ruby (~> 1.2, >= 1.2.0)
130
+ optionable (0.2.0)
131
+ origin (2.1.1)
132
+ polyglot (0.3.5)
133
+ pry (0.10.0)
134
+ coderay (~> 1.1.0)
135
+ method_source (~> 0.8.1)
136
+ slop (~> 3.4)
137
+ rack (1.5.2)
138
+ rack-test (0.6.2)
139
+ rack (>= 1.0)
140
+ rails (4.1.1)
141
+ actionmailer (= 4.1.1)
142
+ actionpack (= 4.1.1)
143
+ actionview (= 4.1.1)
144
+ activemodel (= 4.1.1)
145
+ activerecord (= 4.1.1)
146
+ activesupport (= 4.1.1)
147
+ bundler (>= 1.3.0, < 2.0)
148
+ railties (= 4.1.1)
149
+ sprockets-rails (~> 2.0)
150
+ railties (4.1.1)
151
+ actionpack (= 4.1.1)
152
+ activesupport (= 4.1.1)
153
+ rake (>= 0.8.7)
154
+ thor (>= 0.18.1, < 2.0)
155
+ rake (10.3.2)
156
+ rspec (2.14.1)
157
+ rspec-core (~> 2.14.0)
158
+ rspec-expectations (~> 2.14.0)
159
+ rspec-mocks (~> 2.14.0)
160
+ rspec-core (2.14.8)
161
+ rspec-expectations (2.14.5)
162
+ diff-lcs (>= 1.1.3, < 2.0)
163
+ rspec-mocks (2.14.6)
164
+ ryansch-andand (1.3.2)
165
+ sass (3.2.19)
166
+ sass-rails (4.0.3)
167
+ railties (>= 4.0.0, < 5.0)
168
+ sass (~> 3.2.0)
169
+ sprockets (~> 2.8, <= 2.11.0)
170
+ sprockets-rails (~> 2.0)
171
+ slop (3.5.0)
172
+ sprockets (2.11.0)
173
+ hike (~> 1.2)
174
+ multi_json (~> 1.0)
175
+ rack (~> 1.0)
176
+ tilt (~> 1.1, != 1.3.0)
177
+ sprockets-rails (2.1.3)
178
+ actionpack (>= 3.0)
179
+ activesupport (>= 3.0)
180
+ sprockets (~> 2.8)
181
+ susy (1.0.9)
182
+ compass (>= 0.12.2)
183
+ sass (>= 3.2.0)
184
+ syntax (1.2.0)
185
+ thor (0.19.1)
186
+ thread_safe (0.3.4)
187
+ tilt (1.4.1)
188
+ treetop (1.4.15)
189
+ polyglot
190
+ polyglot (>= 0.3.1)
191
+ tzinfo (1.2.1)
192
+ thread_safe (~> 0.1)
193
+ virtus (1.0.2)
194
+ axiom-types (~> 0.1)
195
+ coercible (~> 1.0)
196
+ descendants_tracker (~> 0.0.3)
197
+ equalizer (~> 0.0.9)
198
+ yajl-ruby (1.2.1)
199
+
200
+ PLATFORMS
201
+ ruby
202
+
203
+ DEPENDENCIES
204
+ appraisal (= 1.0.0.beta3)
205
+ bundler (~> 1.6)
206
+ database_cleaner
207
+ mongoid (~> 4.0.0.beta1)
208
+ pry
209
+ quby!
210
+ quby-mongoid!
211
+ rake
212
+ rspec (~> 2.14.0)
@@ -0,0 +1,82 @@
1
+ require 'quby'
2
+ require 'quby/answer_repos'
3
+ require 'mongoid'
4
+
5
+ module Quby
6
+ module AnswerRepos
7
+ class MongoidRepo < AnswerRepo
8
+ class Record
9
+ include ::Mongoid::Document
10
+ include ::Mongoid::Timestamps
11
+
12
+ if ::Mongoid::VERSION > '4'
13
+ store_in collection: :answers
14
+ field :_id, type: String,
15
+ pre_processed: true,
16
+ default: -> { BSON::ObjectId.new.to_s }
17
+ elsif ::Mongoid::VERSION > '3'
18
+ store_in collection: :answers
19
+ field :_id, type: String,
20
+ pre_processed: true,
21
+ default: -> { Moped::BSON::ObjectId.new.to_s }
22
+ else
23
+ store_in 'answers'
24
+ identity type: String
25
+ end
26
+
27
+ field :questionnaire_id, type: Integer
28
+ field :questionnaire_key, type: String
29
+ field :raw_params, type: Hash
30
+ field :value, type: Hash
31
+ field :import_notes, type: Hash
32
+ field :patient, type: Hash, default: {}
33
+ field :token, type: String
34
+ field :active, type: Boolean, default: true
35
+ field :test, type: Boolean, default: false
36
+ field :completed_at, type: Time
37
+ field :outcome_generated_at, type: Time
38
+ field :scores, type: Hash, default: {}
39
+ field :actions, type: Hash, default: {}
40
+ field :completion, type: Hash, default: {}
41
+ field :dsl_last_update, type: Time
42
+ end
43
+
44
+ def find_completed_after(time, answer_ids)
45
+ records = Record.any_in(_id: answer_ids).where(:completed_at.gt => time)
46
+ records.map { |record| entity(record) }
47
+ end
48
+
49
+ def update!(answer)
50
+ record = find_record(answer.id)
51
+ # MongoDB won't save new hash order if we don't clear it first.
52
+ record.update_attributes!(scores: {}, actions: {}, completion: {})
53
+ update_attributes(record, answer)
54
+ store_record(record)
55
+ end
56
+
57
+ private
58
+
59
+ def all_records(questionnaire_key)
60
+ Record.where(questionnaire_key: questionnaire_key).all.to_a
61
+ end
62
+
63
+ def find_record(id)
64
+ Record.find(id)
65
+ rescue ::Mongoid::Errors::DocumentNotFound, ::Mongoid::Errors::InvalidFind
66
+ raise AnswerNotFound, "Answer #{id.inspect} could not be found."
67
+ end
68
+
69
+ def build_record
70
+ Record.new
71
+ end
72
+
73
+ def store_record(record)
74
+ record.save!
75
+ end
76
+
77
+ def entity(record)
78
+ Quby::Answer.new(record.attributes).tap(&:enhance_by_dsl)
79
+ end
80
+ end
81
+ end
82
+ end