custom_fielder 0.7.4 → 0.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/custom_fielder/custom_fieldable.rb +6 -31
- data/lib/custom_fielder/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8efc430192e902dcb9c7fb03094ff07a0f0352fd
|
|
4
|
+
data.tar.gz: f64aa52d1ff99c0d55564f2994ad0daaf613abf6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 44274b541b02acba72f55f1af3cf99fdcecac934ec35a742379696988d22d23eb1cd9b9e9ce893d0f3c9df15e01d928fdfd3f486f0c51f2eb13f1cfb3ca7c178
|
|
7
|
+
data.tar.gz: b2e9f556c91e8b1f8422e8e58bdaff85ff481ab598cf876995842d1f162578e693f7b7b4c7497493b54bd883da65e34ce08a7d88c074816a76489ee73cff7b4c
|
|
@@ -43,7 +43,7 @@ module CustomFielder
|
|
|
43
43
|
#
|
|
44
44
|
# @return [Array]
|
|
45
45
|
#
|
|
46
|
-
def self.
|
|
46
|
+
def self.custom_fieldable_columns
|
|
47
47
|
[:id]
|
|
48
48
|
end
|
|
49
49
|
|
|
@@ -57,45 +57,20 @@ module CustomFielder
|
|
|
57
57
|
#
|
|
58
58
|
# @return [ActiveRecord::Relation]
|
|
59
59
|
#
|
|
60
|
-
def self.
|
|
60
|
+
def self.custom_fieldable_search
|
|
61
61
|
all
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
##
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
-
# the sub query to find objects and then using this query
|
|
68
|
-
# to join the values with the objects if they exist (in one transaction)
|
|
65
|
+
# Gets all the avaiable fieldable objects for a model
|
|
66
|
+
# that do not already have a value defined on them
|
|
69
67
|
#
|
|
70
68
|
# @param field [CustomFielder::Field] field to search for values on
|
|
71
69
|
#
|
|
72
70
|
# @return [Array<Hash>]
|
|
73
71
|
#
|
|
74
|
-
def self.
|
|
75
|
-
|
|
76
|
-
sub_query = custom_fielder_search.select(object_columns).to_sql
|
|
77
|
-
|
|
78
|
-
object_columns.map! { |column| "objects.#{column} AS #{column}" }
|
|
79
|
-
|
|
80
|
-
query = <<-SQL
|
|
81
|
-
SELECT
|
|
82
|
-
\ #{object_columns.join(', ')},
|
|
83
|
-
cfv.id AS value_id,
|
|
84
|
-
cfv.value AS value,
|
|
85
|
-
'#{field.id}' AS field_id
|
|
86
|
-
FROM (#{sub_query}) objects
|
|
87
|
-
LEFT OUTER JOIN custom_fielder_values cfv
|
|
88
|
-
ON objects.id = cfv.fieldable_id
|
|
89
|
-
AND cfv.field_id = '#{field.id}'
|
|
90
|
-
SQL
|
|
91
|
-
|
|
92
|
-
objects = ActiveRecord::Base.connection.execute(query)
|
|
93
|
-
|
|
94
|
-
if objects.class == PG::Result
|
|
95
|
-
objects = objects.values.map { |values| Hash[objects.fields.zip(values)] }
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
return objects
|
|
72
|
+
def self.custom_fieldable_objects(field)
|
|
73
|
+
custom_fieldable_search.where.not(id: field.values.select(:fieldable_id))
|
|
99
74
|
end
|
|
100
75
|
|
|
101
76
|
##
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: custom_fielder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.7.
|
|
4
|
+
version: 0.7.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nick Hurst
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-07-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|