klastera 1.4.2 → 1.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc8d3414d044460f33127e9eef4f0cb7cc6e6b83333697a944e5248cfe4970fd
4
- data.tar.gz: 063dbb2a15f6b98b0219ac5af5059b40fa1da440c2e298a6140be4637ad1a504
3
+ metadata.gz: e524bc600751df634962778af44d6b9bd782cabdf7a125a145d2a7efbfbe6950
4
+ data.tar.gz: ab457168729e69d5f1ca94f40ea667b78e3610993eaa686998e8aa792f865db1
5
5
  SHA512:
6
- metadata.gz: af3e0d45ee32b14aa1f5b5bb27b246af015bfd6191b93846e52ca5e7789d245c7f068dc741afaa872a76244059dd31e71d543a8c1c8696c0346d183ac1bbb90b
7
- data.tar.gz: 715adddc9f158ceb9c5eaa60e1318c986355d3f8a9e0c875b72903c053cc21fcf207cae038aefac9a51c4e65ffcf4a76ee13047e4a7dd70f908bcdbb0f202428
6
+ metadata.gz: f30c250c13e081a7aebeb66fce89386638d445a92f5dd995c4855483a45efd7bf7927265980fff8ffcef7ca3e9d3f5fc53c618b05babc92464a6986a8878df84
7
+ data.tar.gz: 97007ff678bbc223506ac5fc53814c9b7363c3e45ba4f39455f73d8abdd1012bab6fd7b126b3237cc42b91fbbb6a969061c72ece12549aa1d84ae0810522a43a
@@ -79,9 +79,8 @@ module Klastera
79
79
  # cluster_filter_id is present when the optional_suborganization mode is on. BUT!
80
80
  # Be aware that if the cluster_filter is not present, the value of force_cluster_clause
81
81
  # will be overridden by the returned value of cannot_skip_cluster_clause? method.
82
- #
83
- def cluster_scope!(scope_klass, user, organization, cluster_filter=nil, force_cluster_clause=false)
84
- scope_klass = scope_class(scope_klass)
82
+ def should_clusterize_scope?(user, organization, cluster_filter=nil, force_cluster_clause=false)
83
+ should = false # I don't know if this is a good idea
85
84
  if organization.is_in_cluster_mode? && ( cluster_filter.present? || force_cluster_clause = user.cannot_skip_cluster_clause? ) # yes, this is an assignation
86
85
  cluster_ids = []
87
86
  # Set another variable as array to get the cluster id(s)
@@ -92,15 +91,27 @@ module Klastera
92
91
  end
93
92
  # We will avoid the query unless cluster_ids is having values OR force_cluster_clause is set (see method description)
94
93
  if cluster_ids.present? || force_cluster_clause
95
- scope_klass = scope_klass.eager_load(:organization,cluster_entities: :cluster)
96
94
  # We add the unclustered if the value of cluster_filter have the special without_cluster string or as method description says
97
95
  if cluster_ids.delete(UNCLUSTERED_ENTITY) || ( force_cluster_clause && organization.optional_suborganization_mode? )
98
96
  cluster_ids << nil
99
97
  end
100
- scope_klass = scope_klass.where( cluster_entities: { cluster_id: cluster_ids } )
98
+ should = true
99
+ end
100
+ end
101
+ yield(should,cluster_ids)
102
+ end
103
+
104
+ #
105
+ # The cleanest and fast way to clusterize a entity!
106
+ #
107
+ def cluster_scope!(scope_klass, user, organization, cluster_filter=nil, force_cluster_clause=false)
108
+ scope = scope_class(scope_klass)
109
+ should_clusterize_scope?(user,organization,cluster_filter,force_cluster_clause) do |should,cluster_ids|
110
+ if should
111
+ scope = scope.eager_load(:organization,cluster_entities: :cluster).where( cluster_entities: { cluster_id: cluster_ids } )
101
112
  end
102
113
  end
103
- scope_klass.where(organization_id: organization)
114
+ scope.where(organization_id: organization)
104
115
  end
105
116
 
106
117
 
@@ -1,3 +1,3 @@
1
1
  module Klastera
2
- VERSION = "1.4.2"
2
+ VERSION = "1.4.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klastera
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gino Barahona
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-07 00:00:00.000000000 Z
11
+ date: 2020-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails