polymorphic_belongs_to 0.1.0 → 0.2.0

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: 290d53bdaab6800f56b0edf83ea87a690baf62ca3a271780b6825c95528dd05f
4
- data.tar.gz: bfa1cc5b60ede65a5d744447858dff62830ceef4fe33c8f3d82758792cb725c3
3
+ metadata.gz: b1931a69a1ca4d6916e27182f40285e34d7a6d84d55796ff19c35faa0d91c425
4
+ data.tar.gz: cb2778380cf8c93d0846356562dc98a0d47411c13d686c41561517da208ebaef
5
5
  SHA512:
6
- metadata.gz: d871be11f602c84d9be9a4aa4bf1c5f16bf47f8b79150ff88e878cb433eb1d8a5825baff9d9e19e7256788029925e8a0d28a9b6e30b63cf6f422d7e371100e55
7
- data.tar.gz: 14139961b813f91033316cc9ea3eaaf1220b28bd8afc4cfdadd145a84285489c4799a0908e14a37c53a5ab3ae7de320ecf3f80507cc11be86348fa6a88188245
6
+ metadata.gz: e6cb3727467ec304122f5c0ca97f9b38a79f23d7837ff68f2eee2fcc3971f826d67f3498eb07ae83deac3c3f6edb131f011936b33f1ab13ea7dcff87c355067c
7
+ data.tar.gz: e47a40c40f3a9c092e2592d5b4d4154b47650a28b4cd076fe0a29da7f8d316707a868966a9df59056a04ab960b35593834e26590c79d9618ad5d9bfd5637b5c8
data/README.md CHANGED
@@ -16,13 +16,13 @@ bundle add polymorphic_belongs_to
16
16
  class Comment < ApplicationRecord
17
17
  include PolymorphicBelongsTo
18
18
 
19
- polymorphically_belongs_to :commentable, types: [Post, Photo]
19
+ polymorphic_belongs_to :commentable, types: [Post, Photo]
20
20
 
21
21
  # Disable the "type inclusion" validator
22
- polymorphically_belongs_to :commentable, types: [Post, Photo], validate_types: false
22
+ polymorphic_belongs_to :commentable, types: [Post, Photo], validate_types: false
23
23
 
24
24
  # Customize the "type inclusion" validator
25
- polymorphically_belongs_to :commentable,
25
+ polymorphic_belongs_to :commentable,
26
26
  types: [Post, Photo],
27
27
  validate_types: { in: ["Post", "Photo", "Repost"], message: "..." }
28
28
  end
@@ -32,7 +32,7 @@ Run `bin/tapioca dsl` to regenerate RBIs.
32
32
 
33
33
  ### Options
34
34
 
35
- `polymorphically_belongs_to(name, types:, validate_types: true, optional: nil, **options)`
35
+ `polymorphic_belongs_to(name, types:, validate_types: true, optional: nil, **options)`
36
36
 
37
37
  - `name` — The association name, e.g. `:commentable`.
38
38
  - `types:` — An array of allowed target classes. Used both as the source of truth for the type-inclusion validator and by the Tapioca DSL compiler when generating RBIs.
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module PolymorphicBelongsTo
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
@@ -10,15 +10,15 @@ module PolymorphicBelongsTo
10
10
  extend ActiveSupport::Concern
11
11
 
12
12
  included do
13
- class_attribute :defined_polymorphic_belongs_tos, instance_writer: false
13
+ class_attribute :polymorphic_belongs_to_types, instance_writer: false
14
14
  end
15
15
 
16
16
  module ClassMethods
17
- def polymorphically_belongs_to(name, types:, validate_types: true, **options)
17
+ def polymorphic_belongs_to(name, types:, validate_types: true, **options)
18
18
  name = name.to_sym
19
19
 
20
- self.defined_polymorphic_belongs_tos ||= {}
21
- defined_polymorphic_belongs_tos[name.to_s] = types
20
+ self.polymorphic_belongs_to_types ||= {}
21
+ polymorphic_belongs_to_types[name.to_s] = types
22
22
 
23
23
  belongs_to(name, polymorphic: true, **options)
24
24
 
@@ -15,12 +15,12 @@ module Tapioca
15
15
  def self.gather_constants
16
16
  all_classes.select do |klass|
17
17
  klass < ActiveRecord::Base &&
18
- klass.respond_to?(:defined_polymorphic_belongs_tos)
18
+ klass.respond_to?(:polymorphic_belongs_to_types)
19
19
  end
20
20
  end
21
21
 
22
22
  def decorate
23
- defined = T.unsafe(constant).defined_polymorphic_belongs_tos
23
+ defined = T.unsafe(constant).polymorphic_belongs_to_types
24
24
  return unless defined&.any?
25
25
 
26
26
  root.create_path(constant) do |model|
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Zach Ahn"]
10
10
  spec.email = ["engineering@zachahn.com"]
11
11
 
12
- spec.summary = "PolymorphicBelongsTo provides a type-safe `polymorphically_belongs_to` association to ActiveRecord. Relies on Sorbet + Tapioca."
12
+ spec.summary = "PolymorphicBelongsTo provides a type-safe `polymorphic_belongs_to` association to ActiveRecord. Relies on Sorbet + Tapioca."
13
13
  spec.homepage = "https://github.com/zachahn/polymorphic_belongs_to"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = ">= 3.2.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polymorphic_belongs_to
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Ahn
@@ -85,6 +85,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  requirements: []
86
86
  rubygems_version: 3.6.9
87
87
  specification_version: 4
88
- summary: PolymorphicBelongsTo provides a type-safe `polymorphically_belongs_to` association
88
+ summary: PolymorphicBelongsTo provides a type-safe `polymorphic_belongs_to` association
89
89
  to ActiveRecord. Relies on Sorbet + Tapioca.
90
90
  test_files: []