no_fly_list 0.7.2 → 0.7.4

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: 9fb7865780acd9586b0ff700686a1546a4c294f9fc3d7a71fe47f2fb7a6def0c
4
- data.tar.gz: be5186e8116c5db42c4aa4e3536ab4343b95967f5cd05dcfb64c8f99ebb85270
3
+ metadata.gz: 7a4d0bb308f36212383e565010061a086173ddbd9105fad575193d7abca8ffa5
4
+ data.tar.gz: 92772d14d0351c3a7a0d1e631d81590fb0a87e49460773cd68e78368ef55906b
5
5
  SHA512:
6
- metadata.gz: 630d2aa00cc4b2465321d1040697cff6c54124247275a0b75677d70653fe347ec1c0ad7e9c573dea060de07be1de02977f1ff6f467bfe1465299a1f764e35325
7
- data.tar.gz: 1201844673a3893a3c760ab1fc88ed6826839d799bca6a93b17c2c3e802fa4e9df4d485bdc5511cec4c7cbf2bdcc3cba9cfd1280970d58b5eaa93492f7ece67a
6
+ metadata.gz: 793849ef8f48b2ced0c5547187fa02cc704b05bb6ebad05b65c2d7e21780ab6b2efa6349a97ef74af310ef49afa28c79506ee431f45b74613bc9038482ebf970
7
+ data.tar.gz: 963dd7b6d64a7b159bc4085a6ea80f3641730a108dc820a91bb9201b8e636ac5705e07f4a561a6fa1089d377866ef9fbf0c55d2018796f1bd8a9750573584c85
@@ -82,8 +82,6 @@ module NoFlyList
82
82
 
83
83
  # Creates a new tagging class with appropriate configuration
84
84
  def create_tagging_class(setup, base_class)
85
- setup.context.to_s.singularize
86
-
87
85
  Class.new(base_class) do
88
86
  self.table_name = "#{setup.taggable_klass.table_name.singularize}_taggings"
89
87
 
@@ -173,21 +171,26 @@ module NoFlyList
173
171
  end
174
172
 
175
173
  # Set up tagging class associations
176
- setup.tagging_class_name.constantize.class_eval do
177
- belongs_to :tag,
178
- class_name: setup.tag_class_name,
179
- foreign_key: "tag_id"
180
-
181
- # For local tags, we use a simple belongs_to without polymorphic
182
- belongs_to :taggable,
183
- class_name: setup.taggable_klass.name,
184
- foreign_key: "taggable_id"
185
-
186
- validates :tag, :taggable, :context, presence: true
187
- validates :tag_id, uniqueness: {
188
- scope: %i[taggable_id context],
189
- message: "has already been tagged on this record in this context"
190
- }
174
+ # Guard belongs_to to prevent STI subclasses from overwriting
175
+ # the base class association on a shared tagging class
176
+ tagging_klass = setup.tagging_class_name.constantize
177
+ existing_taggable = tagging_klass.reflect_on_association(:taggable)
178
+ if existing_taggable.nil? || existing_taggable.class_name == setup.taggable_klass.name
179
+ tagging_klass.class_eval do
180
+ belongs_to :tag,
181
+ class_name: setup.tag_class_name,
182
+ foreign_key: "tag_id"
183
+
184
+ belongs_to :taggable,
185
+ class_name: setup.taggable_klass.name,
186
+ foreign_key: "taggable_id"
187
+
188
+ validates :tag, :taggable, :context, presence: true
189
+ validates :tag_id, uniqueness: {
190
+ scope: %i[taggable_id context],
191
+ message: "has already been tagged on this record in this context"
192
+ }
193
+ end
191
194
  end
192
195
  end
193
196
 
@@ -238,11 +241,7 @@ module NoFlyList
238
241
  # Define helper methods module for this context
239
242
  helper_module = Module.new do
240
243
  define_method :create_and_set_proxy do |instance_variable_name, setup|
241
- tag_model = if setup.polymorphic
242
- setup.tag_class_name.constantize
243
- else
244
- self.class.const_get("#{self.class.name}Tag")
245
- end
244
+ tag_model = setup.tag_class_name.constantize
246
245
 
247
246
  proxy = TaggingProxy.new(
248
247
  self,
@@ -59,7 +59,12 @@ module NoFlyList
59
59
 
60
60
  proxy = instance_variable_get(var)
61
61
  next if proxy.nil?
62
- return false unless proxy.save
62
+ unless proxy.save
63
+ proxy.errors.each do |error|
64
+ errors.add(:base, error.message)
65
+ end
66
+ throw :abort
67
+ end
63
68
  end
64
69
  true
65
70
  ensure
@@ -332,11 +332,12 @@ module NoFlyList
332
332
 
333
333
  def current_list_from_database
334
334
  if setup[:polymorphic]
335
- tagging_table = setup[:tagging_class_name].tableize
335
+ tagging_klass = setup[:tagging_class_name].constantize
336
+ tagging_table = tagging_klass.arel_table
337
+
336
338
  @model.send(@context.to_s)
337
- .joins("INNER JOIN #{tagging_table} ON #{tagging_table}.tag_id = tags.id")
338
- .where("#{tagging_table}.taggable_type = ? AND #{tagging_table}.taggable_id = ?",
339
- @model.class.name, @model.id)
339
+ .where(tagging_table[:taggable_type].eq(@model.class.name))
340
+ .where(tagging_table[:taggable_id].eq(@model.id))
340
341
  .pluck(:name)
341
342
  else
342
343
  @model.send(@context.to_s).pluck(:name)
@@ -345,7 +346,7 @@ module NoFlyList
345
346
 
346
347
  def set_list(_context, value)
347
348
  @clear_operation = false
348
- @pending_changes = transformer.parse_tags(value)
349
+ @pending_changes = transformer.parse_tags(value).uniq.reject(&:blank?)
349
350
  mark_record_dirty
350
351
  valid? # Just check validity without raising
351
352
  self
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NoFlyList
4
- VERSION = "0.7.2"
4
+ VERSION = "0.7.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: no_fly_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
@@ -23,7 +23,8 @@ dependencies:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: '7.2'
26
- description: Tagging system for ActiveRecord models inspired by the TSA
26
+ description: A flexible, high-performance tagging system for Rails applications with
27
+ support for polymorphic tags, custom transformers, and database-specific optimizations
27
28
  email:
28
29
  - terminale@gmail.com
29
30
  executables: []
@@ -66,7 +67,12 @@ homepage: https://github.com/contriboss/no_fly_list
66
67
  licenses:
67
68
  - MIT
68
69
  metadata:
70
+ homepage_uri: https://github.com/contriboss/no_fly_list
71
+ source_code_uri: https://github.com/contriboss/no_fly_list
72
+ changelog_uri: https://github.com/contriboss/no_fly_list/blob/master/CHANGELOG.md
73
+ bug_tracker_uri: https://github.com/contriboss/no_fly_list/issues
69
74
  rubygems_mfa_required: 'true'
75
+ github_repo: ssh://github.com/contriboss/no_fly_list
70
76
  rdoc_options: []
71
77
  require_paths:
72
78
  - lib
@@ -83,5 +89,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
89
  requirements: []
84
90
  rubygems_version: 3.6.9
85
91
  specification_version: 4
86
- summary: Tagging system for ActiveRecord models
92
+ summary: Modern tagging system for Rails 7.2+ applications
87
93
  test_files: []