association_scope 0.3.3 → 0.4.0

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: 4a78d72190a884c263ac9dac8d02588505bf530168c8e15faff4a3d3f07e53ad
4
- data.tar.gz: ccd5422df4c1c871dacb0b0b8954abffb580ac305d639a8b91438f6ceb8abb85
3
+ metadata.gz: 67d2f037f4c3007105757fe5b90f5307eb56614979e7cd4fa83d9036b5584321
4
+ data.tar.gz: d775072058420799584cf18dc27d80c246070dfd2ae1246e084f0a25acf3aa44
5
5
  SHA512:
6
- metadata.gz: 539e2a97b60ecf359a717e8dd4de6a203d16ea91e2fb61dd7a520bb599b79a4b7a5ac742a63f33bddbf199bc4565dfb728c85994cd30e5733a307e915d53ed1d
7
- data.tar.gz: f2d1f90636e1e2f5aca7231ef8c8d686d276d5a341b02e6a5b70af77ad7b1c5500bf5ac1c45b64624e12315add3e6ffdbb72d61fddd5adc48e98c3216cd3db6a
6
+ metadata.gz: 5aa81882d47e6207b82deb659f43f3010e83d985fe1bed9a411e29c5796082509c4d19f4435bfdbb9d8a636878c06ac3dde49e7543bf5f7b7db38ec4583d0504
7
+ data.tar.gz: 22d3f940c21d6e1722eef994d0294a80d6e3f80a87a3bbadba1f457f1eeb6ef54fecc6ef3c9d761100213dcdc669f04c5f242cc8e95f4546151639f15727eb25
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AssociationScope
4
+ class PolymorphicAssociationError < StandardError
5
+ attr_accessor :association,
6
+ :model
7
+
8
+ def initialize(association: nil, model: nil)
9
+ @association = association
10
+ @model = model
11
+ end
12
+
13
+ def message
14
+ "Association :#{association} is polymorph in #{model}!"
15
+ end
16
+ end
17
+ end
@@ -4,6 +4,10 @@ module AssociationScope
4
4
  class Scope
5
5
  class BelongsToReflection < Scope
6
6
  def apply
7
+ if reflection_details.options[:polymorphic]
8
+ raise PolymorphicAssociationError.new association: association, model: model
9
+ end
10
+
7
11
  association = @association
8
12
  class_name = reflection_details.options[:class_name]&.constantize || association.camelize.constantize
9
13
  foreign_key = reflection_details.options[:foreign_key]
@@ -7,9 +7,9 @@ module AssociationScope
7
7
  class_name = reflection_details.options[:class_name]&.constantize || association.singularize.camelize.constantize
8
8
 
9
9
  association = @association.pluralize
10
- column_name = model.to_s.underscore
10
+ column_name = reflection_details.options[:as] || model.to_s.underscore
11
11
 
12
- raise AssociationMissingError.new(missing_in: class_name, association: column_name) unless class_name.reflections.has_key?(column_name)
12
+ raise AssociationMissingError.new(missing_in: class_name, association: column_name) unless class_name.reflections.has_key?(column_name.to_s)
13
13
 
14
14
  model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
15
15
  scope association, -> do
@@ -39,7 +39,7 @@ module AssociationScope
39
39
  end
40
40
 
41
41
  def compute_second_join class_name
42
- if %w[HasOneReflection BelongsToReflection].include?(reflection_type class_name)
42
+ if %w[HasOneReflection BelongsToReflection].include?(reflection_type(class_name))
43
43
  model.to_s.underscore.to_sym
44
44
  else
45
45
  model.to_s.underscore.pluralize.to_sym
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AssociationScope
4
- VERSION = "0.3.3"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -9,6 +9,7 @@ require "association_scope/scope/has_and_belongs_to_many_reflection"
9
9
  require "association_scope/scope/through_reflection"
10
10
 
11
11
  require "association_scope/errors/association_missing_error"
12
+ require "association_scope/errors/polymorphic_association_error"
12
13
 
13
14
  module AssociationScope
14
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: association_scope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - datae
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: awesome_print
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.9.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.9.2
69
83
  description: AssociationScope adds useful scopes targeting Associations in ActiveRecord.
70
84
  email:
71
85
  - accounts@datae.de
@@ -78,6 +92,7 @@ files:
78
92
  - Rakefile
79
93
  - lib/association_scope.rb
80
94
  - lib/association_scope/errors/association_missing_error.rb
95
+ - lib/association_scope/errors/polymorphic_association_error.rb
81
96
  - lib/association_scope/scope.rb
82
97
  - lib/association_scope/scope/belongs_to_reflection.rb
83
98
  - lib/association_scope/scope/has_and_belongs_to_many_reflection.rb
@@ -107,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
122
  - !ruby/object:Gem::Version
108
123
  version: '0'
109
124
  requirements: []
110
- rubygems_version: 3.2.9
125
+ rubygems_version: 3.2.25
111
126
  signing_key:
112
127
  specification_version: 4
113
128
  summary: AssociationScope adds useful scopes targeting Associations in ActiveRecord.