abstractor 1.0.14 → 1.0.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YWYyNzk5NjkxOTcyZjMyZjg2MDM0OWQ0MzgwZWVhZTZkMGFhMzY4OA==
4
+ NmMxMzYzMjdiMmFjODc2MDU0YTBiNDcwYmQ0MGQ2YWVmMjE4ZTA1Zg==
5
5
  data.tar.gz: !binary |-
6
- ZWYxNTJlNjA1NDYzYjJkMDdjOTYzMDk5NjMyMjM5NTRhOTYyNmQ3ZA==
6
+ ZDRmNzc4NWVmN2IwNDVlMDUxMmE4ZDc3OWIyNTMyNmQ2ZTA0MjU0MQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MTNhZDQ1Mzg0MzRiYTI4Nzc4ODE3ZTFiMmMzZWRhNzE3NjlmNzA2NTQ1MjAy
10
- YzhlMTJhN2IxMWFlODA5YjdjMjliOWEwYTI2Y2ZiZGFkNGRhZGYxNzliODBk
11
- M2U1ZTk4MjE4Zjk0ZmU4MGY1MmZlMjhlZWE2YzQxODhmNDY0ZDM=
9
+ MGQzNmYxYzFhOGNhYzJjODQ3NTc1YTUwMTUxYmQ0NDY1YTAzY2E3OTRlYWY4
10
+ MzU2MTY1NGM2ODExYjA0NWRmMDdhN2MxMmNiM2MxZmFmNmI5ZmNiYmNiNGQw
11
+ MTk2Nzk0ZmI1YmI0ZGE3MzBmMmY0YjViOWNkYzRiMTRjNjg1ZWE=
12
12
  data.tar.gz: !binary |-
13
- OTI1ZTUyZGQ3YzAxZDVjNDUxNjdhOGZmY2MyOTE0Y2NjNzJlYzlkOGJiZWJj
14
- MTc4MTE1ZTU3MmEyY2UzNzk1YjQ4ODAzMmIzNDYzZDQ3ODhhZDljYzNjZTlh
15
- ZmQ3MGEzMmI0ZDk5ZTg3ODZmNmI1NzFiODQwZjUzOTlkMjgwZTc=
13
+ OWVjYzMyMWZlNzBhMDhlMmE5NGQ2ZDJlOWQxMTRhYjk3MjM1YzgxMzVjZWFl
14
+ YTlkNTY2Y2E4ZThmOTRhODgyNzFjY2Y5NWFiZDIxYzE2NzJiZmU4ZjQzMjgy
15
+ ODU0ZDFkOTVjN2Q3Y2VjNjc1MmNmMTFmMmUyZjQ4MTI2NTJlOWI=
@@ -136,29 +136,16 @@ module Abstractor
136
136
  # @return ActiveRecord::Relation
137
137
  def pivot_abstractions
138
138
  select = prepare_pivot_select(grouped: false)
139
- joins = "LEFT JOIN
140
- (
141
- SELECT #{self.table_name}.id AS subject_id,
142
- #{select}
143
- FROM
144
- (SELECT aas.predicate
145
- , aas.id AS abstractor_abstraction_schema_id
146
- , asb.subject_type
147
- , aa.about_id
148
- , aa.value
149
- FROM abstractor_abstractions aa JOIN abstractor_subjects asb ON aa.abstractor_subject_id = asb.id
150
- JOIN abstractor_abstraction_schemas aas ON asb.abstractor_abstraction_schema_id = aas.id
151
- WHERE asb.subject_type = '#{self.to_s}'
152
- AND NOT EXISTS (
153
- SELECT 1
154
- FROM abstractor_abstraction_group_members aagm
155
- WHERE aa.id = aagm.abstractor_abstraction_id
156
- )
157
- ) data join #{self.table_name} ON data.about_id = #{self.table_name}.id
158
- GROUP BY #{self.table_name}.id
159
- ) pivoted_abstractions ON pivoted_abstractions.subject_id = #{self.table_name}.id
160
- "
161
- joins(joins).select("#{self.table_name}.*, pivoted_abstractions.*")
139
+ adapter = ActiveRecord::Base.connection.instance_values["config"][:adapter]
140
+ j = case adapter
141
+ when 'sqlite3'
142
+ prepare_pivot_joins(select, "'t'")
143
+ when 'sqlserver'
144
+ prepare_pivot_joins(select, '1')
145
+ when 'postgresql'
146
+ prepare_pivot_joins(select, 'true')
147
+ end
148
+ joins(j).select("#{self.table_name}.*, pivoted_abstractions.*")
162
149
  end
163
150
 
164
151
  ##
@@ -181,30 +168,17 @@ module Abstractor
181
168
  # @return ActiveRecord::Relation
182
169
  # @see Abstractor::Methods::Models:AbstractorSubjectGroup
183
170
  def pivot_grouped_abstractions(abstractor_subject_groups_name)
184
- abstractor_subject_group = abstractor_subject_groups.detect { |abstractor_subject_group| abstractor_subject_group.name == abstractor_subject_groups_name }
185
171
  select = prepare_pivot_select(grouped: true)
186
- joins = "JOIN
187
- (
188
- SELECT #{self.table_name}.id AS subject_id,
189
- #{select}
190
- FROM
191
- (SELECT aas.predicate
192
- , aas.id AS abstraction_schema_id
193
- , asb.subject_type
194
- , aa.about_id
195
- , aa.value
196
- , aag.id AS abstractor_abstraction_group_id
197
- FROM abstractor_abstractions aa JOIN abstractor_subjects asb ON aa.abstractor_subject_id = asb.id
198
- JOIN abstractor_abstraction_schemas aas ON asb.abstractor_abstraction_schema_id = aas.id
199
- JOIN abstractor_abstraction_group_members aagm ON aa.id = aagm.abstractor_abstraction_id
200
- JOIN abstractor_abstraction_groups aag ON aagm.abstractor_abstraction_group_id= aag.id
201
- WHERE asb.subject_type = '#{self.to_s}'
202
- AND aag.abstractor_subject_group_id = #{abstractor_subject_group.id}
203
- ) data join #{self.table_name} ON data.about_id = #{self.table_name}.id
204
- GROUP BY #{self.table_name}.id, abstractor_abstraction_group_id
205
- ) pivoted_abstractions ON pivoted_abstractions.subject_id = #{self.table_name}.id
206
- "
207
- joins(joins).select("#{self.table_name}.*, pivoted_abstractions.*")
172
+ adapter = ActiveRecord::Base.connection.instance_values["config"][:adapter]
173
+ j = case adapter
174
+ when 'sqlite3'
175
+ prepare_grouped_pivot_joins(select, "'t'", abstractor_subject_groups_name)
176
+ when 'sqlserver'
177
+ prepare_grouped_pivot_joins(select, '1', abstractor_subject_groups_name)
178
+ when 'postgresql'
179
+ prepare_grouped_pivot_joins(select, 'true', abstractor_subject_groups_name)
180
+ end
181
+ joins(j).select("#{self.table_name}.*, pivoted_abstractions.*")
208
182
  end
209
183
 
210
184
  private
@@ -218,6 +192,57 @@ module Abstractor
218
192
  end
219
193
  select = select.join(',')
220
194
  end
195
+
196
+ def prepare_pivot_joins(select, bool)
197
+ "LEFT JOIN
198
+ (
199
+ SELECT #{self.table_name}.id AS subject_id,
200
+ #{select}
201
+ FROM
202
+ (SELECT aas.predicate
203
+ , aas.id AS abstractor_abstraction_schema_id
204
+ , asb.subject_type
205
+ , aa.about_id
206
+ , CASE WHEN aa.value IS NOT NULL AND aa.value != '' THEN aa.value WHEN aa.unknown = #{bool} THEN 'unknown' WHEN aa.not_applicable = #{bool} THEN 'not applicable' END AS value
207
+ FROM abstractor_abstractions aa JOIN abstractor_subjects asb ON aa.abstractor_subject_id = asb.id
208
+ JOIN abstractor_abstraction_schemas aas ON asb.abstractor_abstraction_schema_id = aas.id
209
+ WHERE asb.subject_type = '#{self.to_s}'
210
+ AND NOT EXISTS (
211
+ SELECT 1
212
+ FROM abstractor_abstraction_group_members aagm
213
+ WHERE aa.id = aagm.abstractor_abstraction_id
214
+ )
215
+ ) data join #{self.table_name} ON data.about_id = #{self.table_name}.id
216
+ GROUP BY #{self.table_name}.id
217
+ ) pivoted_abstractions ON pivoted_abstractions.subject_id = #{self.table_name}.id
218
+ "
219
+ end
220
+
221
+ def prepare_grouped_pivot_joins(select, bool, abstractor_subject_groups_name)
222
+ abstractor_subject_group = abstractor_subject_groups.detect { |abstractor_subject_group| abstractor_subject_group.name == abstractor_subject_groups_name }
223
+
224
+ "JOIN
225
+ (
226
+ SELECT #{self.table_name}.id AS subject_id,
227
+ #{select}
228
+ FROM
229
+ (SELECT aas.predicate
230
+ , aas.id AS abstraction_schema_id
231
+ , asb.subject_type
232
+ , aa.about_id
233
+ , CASE WHEN aa.value IS NOT NULL AND aa.value != '' THEN aa.value WHEN aa.unknown = #{bool} THEN 'unknown' WHEN aa.not_applicable = #{bool} THEN 'not applicable' END AS value
234
+ , aag.id AS abstractor_abstraction_group_id
235
+ FROM abstractor_abstractions aa JOIN abstractor_subjects asb ON aa.abstractor_subject_id = asb.id
236
+ JOIN abstractor_abstraction_schemas aas ON asb.abstractor_abstraction_schema_id = aas.id
237
+ JOIN abstractor_abstraction_group_members aagm ON aa.id = aagm.abstractor_abstraction_id
238
+ JOIN abstractor_abstraction_groups aag ON aagm.abstractor_abstraction_group_id= aag.id
239
+ WHERE asb.subject_type = '#{self.to_s}'
240
+ AND aag.abstractor_subject_group_id = #{abstractor_subject_group.id}
241
+ ) data join #{self.table_name} ON data.about_id = #{self.table_name}.id
242
+ GROUP BY #{self.table_name}.id, abstractor_abstraction_group_id
243
+ ) pivoted_abstractions ON pivoted_abstractions.subject_id = #{self.table_name}.id
244
+ "
245
+ end
221
246
  end
222
247
  end
223
248
  end
@@ -1,3 +1,3 @@
1
1
  module Abstractor
2
- VERSION = '1.0.14'
2
+ VERSION = '1.0.15'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abstractor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.14
4
+ version: 1.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Gurley, Yulia Bushmanova
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-28 00:00:00.000000000 Z
11
+ date: 2014-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails