active_content 0.1.3 → 0.1.4
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4d733346b4391d869a6dc9e82b49a0efd9a4bd0
|
4
|
+
data.tar.gz: 74bd6d1516920cfd6b0da9a0edaedc5b31b44ed0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cde1fc9c0d26f7d55ada8f940b3ead5ebe65a1677c3d1fe22a3b691fdd59ab4a515219a70e9152994d63b64d0e3604065896ae089062fb6a9e36992750dab4b8
|
7
|
+
data.tar.gz: 56f4444c548d83bd095e00f560ede5b4530a7988d7a8e44cc8045c79be3d56ba891e21f3ab9b55686afd778e35870cfc08baef83046519fbca342eba90aae011
|
@@ -8,7 +8,7 @@ module ActiveContent
|
|
8
8
|
options = options.merge(through: :"#{name}_taxonomizations")
|
9
9
|
setting = { as: :taxonomizable, class_name: 'ActiveContent::Taxonomization', autosave: true, dependent: :destroy }
|
10
10
|
|
11
|
-
has_many options[:through], setting
|
11
|
+
has_many options[:through], -> { where field: "#{name}".downcase }, setting
|
12
12
|
has_many name, options
|
13
13
|
|
14
14
|
define_method :"#{name}_list" do
|
@@ -24,25 +24,22 @@ module ActiveContent
|
|
24
24
|
self.send :"#{name}=", names
|
25
25
|
end
|
26
26
|
|
27
|
-
query = self.includes(name)
|
28
|
-
blank = { taxonomies: { id: nil } }
|
29
|
-
|
30
27
|
scope :"with_#{name}", -> (*ids) do
|
31
|
-
|
32
|
-
ids.empty? ? query.where.not(blank) : query.where(id)
|
28
|
+
joins(name).where(taxonomies: { id: ids })
|
33
29
|
end
|
34
30
|
|
35
31
|
scope :"without_#{name}", -> (*ids) do
|
36
|
-
|
37
|
-
ids.empty? ? query.where(blank) : query.where(blank).or(query.where.not(id))
|
32
|
+
joins(name).where.not(taxonomies: { id: ids })
|
38
33
|
end
|
39
34
|
end
|
40
35
|
|
41
36
|
def has_taxonomized(name, options={})
|
42
|
-
assoc_name
|
43
|
-
|
37
|
+
assoc_name = "#{name}".pluralize
|
38
|
+
assoc_field = options[:through] || self.name.parameterize.underscore.pluralize
|
39
|
+
assoc_type = (options[:class_name] || "#{name}".classify).constantize.base_class.name
|
40
|
+
assoc_proc = -> { where taxonomizations: { field: assoc_field } }
|
44
41
|
|
45
|
-
has_many :"#{assoc_name}", through: :taxonomizations, source: :taxonomizable, source_type: "#{assoc_type}"
|
42
|
+
has_many :"#{assoc_name}", assoc_proc, through: :taxonomizations, source: :taxonomizable, source_type: "#{assoc_type}"
|
46
43
|
end
|
47
44
|
end
|
48
45
|
end
|
@@ -12,12 +12,13 @@ class CreateTaxonomies < ActiveRecord::Migration[5.0]
|
|
12
12
|
add_index :taxonomies, :ancestry
|
13
13
|
|
14
14
|
create_table :taxonomizations do |t|
|
15
|
+
t.string :field, null: false
|
15
16
|
t.references :taxonomy
|
16
17
|
t.references :taxonomizable, null: false, polymorphic: true, index: false
|
17
18
|
|
18
19
|
t.timestamps
|
19
20
|
end
|
20
21
|
|
21
|
-
add_index :taxonomizations, [:taxonomizable_id, :taxonomizable_type, :taxonomy_id], unique: true, name: :index_taxonomizations_on_taxonomizable_attribute
|
22
|
+
add_index :taxonomizations, [:taxonomizable_id, :taxonomizable_type, :taxonomy_id, :field], unique: true, name: :index_taxonomizations_on_taxonomizable_attribute
|
22
23
|
end
|
23
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_content
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olibia Tsati
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-11-
|
12
|
+
date: 2017-11-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|