scopiform 0.2.10 → 0.2.12

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
  SHA256:
3
- metadata.gz: cca47f44f585db581edd54791485e5016ecc1d8f73c5e09dc0cb3be21a853d0e
4
- data.tar.gz: fea9cb2762ac42bdcb1089262ac0e116857fb1d568590bb3c570e9b1f49f60d8
3
+ metadata.gz: 4797b03e201890c2061d9d034865c69ad3eeff2659e116072762d916cf9d1a5b
4
+ data.tar.gz: 967d1c00becc5337ea67c70a585eed94b5b9567d873f3b704d64e35082729ff2
5
5
  SHA512:
6
- metadata.gz: fc021d11757854fc08b8d238ffe7f8bdf2300cf94fb2ceb2d5b87720dbb9de977845343007e6f04377b93f1c95ee94cdc6b89c3daa29ac538cfa184aeb4cae72
7
- data.tar.gz: 97669e667b8610924637a185fd5b31c0421f03e54834ccc76fa4ea326fa68ce82e44011ce0c55a47d1f4a2380171c597e5f4c1a7dffca7ed644ee34f0ea8cceb
6
+ metadata.gz: 4e9f003fad523f7807b8019d7cec7b041551c9512cdb0b7db182960d2b7d24cc2b8b944aa3d048fd99545ffd0973550a41f525e76ed9ac768c4653b15eb6d161
7
+ data.tar.gz: e2767c5336ef108e5df62ee94d9ac1cb01475d47680da728d8fbbb164703080ece6ca258f7bbf8edbcf5cc3739fef510ca4709fa836a29cb14c92ee0287735e3
@@ -6,7 +6,7 @@ module Scopiform
6
6
  module Helpers
7
7
  extend ActiveSupport::Concern
8
8
 
9
- STRING_TYPES = %i[string text].freeze
9
+ STRING_TYPES = %i[string text varchar].freeze
10
10
  NUMBER_TYPES = %i[integer float decimal].freeze
11
11
  DATE_TYPES = %i[date time datetime timestamp].freeze
12
12
 
@@ -63,16 +63,16 @@ module Scopiform
63
63
 
64
64
  def safe_columns
65
65
  @safe_columns ||= columns
66
- rescue *safe_column_rescue_errors
67
- logger.warn "Unable to load columns for `#{name}`"
68
- @safe_columns = []
66
+ # rescue *safe_column_rescue_errors
67
+ # logger.warn "Unable to load columns for `#{name}`"
68
+ # @safe_columns = []
69
69
  end
70
70
 
71
71
  def safe_columns_hash
72
72
  @safe_columns_hash ||= columns_hash
73
- rescue *safe_column_rescue_errors
74
- logger.warn "Unable to load columns_hash for `#{name}`"
75
- @safe_columns_hash = {}
73
+ # rescue *safe_column_rescue_errors
74
+ # logger.warn "Unable to load columns_hash for `#{name}`"
75
+ # @safe_columns_hash = {}
76
76
  end
77
77
 
78
78
  private
@@ -1,6 +1,6 @@
1
1
  module Scopiform
2
2
  class ScopeContext
3
- attr_accessor :association, :arel_table, :association_arel_table, :joins, :ancestors, :scopes
3
+ attr_accessor :association, :arel_table, :association_arel_table, :joins, :ancestors, :scopes, :has_manys
4
4
 
5
5
  def self.from(ctx)
6
6
  created = new
@@ -20,6 +20,7 @@ module Scopiform
20
20
  @joins = []
21
21
  @ancestors = []
22
22
  @scopes = []
23
+ @has_manys = []
23
24
  end
24
25
 
25
26
  def set(arel_table)
@@ -35,6 +36,10 @@ module Scopiform
35
36
  self.association = association.through_reflection
36
37
  end
37
38
 
39
+ unless association.has_one? || association.belongs_to?
40
+ has_manys << association.name
41
+ end
42
+
38
43
  ancestors << association.name.to_s.pluralize
39
44
  self.association_arel_table = association.klass.arel_table.alias(alias_name)
40
45
 
@@ -17,10 +17,13 @@ module Scopiform
17
17
 
18
18
  ctx.association = association
19
19
  ctx.build_joins
20
+ has_manys = ctx.has_manys.present?
20
21
 
21
22
  applied = ctx.association.klass.send(method, value, ctx: ScopeContext.from(ctx).set(ctx.association_arel_table))
22
23
 
23
- if is_root
24
+ if is_root && !has_manys
25
+ ctx.scopes.reduce(active_record.joins(ctx.joins).merge(applied)) { |chain, scope| chain.merge(scope) }
26
+ elsif is_root && has_manys
24
27
  ctx.scopes.reduce(active_record.distinct.joins(ctx.joins).merge(applied)) { |chain, scope| chain.merge(scope) }
25
28
  else
26
29
  ctx.scopes.reduce(active_record.all.merge(applied)) { |chain, scope| chain.merge(scope) }
@@ -1,3 +1,3 @@
1
1
  module Scopiform
2
- VERSION = '0.2.10'.freeze
2
+ VERSION = '0.2.12'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scopiform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - jayce.pulsipher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-08 00:00:00.000000000 Z
11
+ date: 2023-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -123,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.7.7
126
+ rubygems_version: 3.0.3
128
127
  signing_key:
129
128
  specification_version: 4
130
129
  summary: Generate scope methods to ActiveRecord classes based on columns and associations