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: 3cb9c9ba1c2461a6a6756106db94041a75a53a6e
4
- data.tar.gz: 65c8989b5e2732c26590c8d900caa081690f4935
3
+ metadata.gz: b4d733346b4391d869a6dc9e82b49a0efd9a4bd0
4
+ data.tar.gz: 74bd6d1516920cfd6b0da9a0edaedc5b31b44ed0
5
5
  SHA512:
6
- metadata.gz: 4b738f0b07040e6df0b15967d51e61047e9b752958ceb1a0f1328f14261c65b61bff0851f41637d9c5eacc8f14e76fa7838446a1b06cc008a0c8694857e4cf41
7
- data.tar.gz: 21ea39f9a3bb162eabc391bbe5125e2992034f9d94fe56f9b1fde0b2ba92975e7b0ab66ecc8a014fb71cbf429730a1271bd3f72a96b63d73efaf71f8fed69a1d
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
- id = { taxonomies: { id: ids } }
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
- id = { taxonomies: { id: ids } }
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 = "#{name}".pluralize
43
- assoc_type = (options[:class_name] || "#{name}".classify).constantize.base_class.name
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
@@ -1,3 +1,3 @@
1
1
  module ActiveContent
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  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.3
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-19 00:00:00.000000000 Z
12
+ date: 2017-11-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord