Skip to content

Commit c0f9886

Browse files
committed
Always use Set[Symbol] for custom associations in AssociationInspector and RunContext.
1 parent 7fd729b commit c0f9886

3 files changed

Lines changed: 7 additions & 9 deletions

File tree

lib/packwerk/association_inspector.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@ module Packwerk
66
class AssociationInspector
77
include ConstantNameInspector
88

9-
#: type custom_associations = Array[Symbol] | Set[Symbol]
10-
119
RAILS_ASSOCIATIONS = [
1210
:belongs_to,
1311
:has_many,
1412
:has_one,
1513
:has_and_belongs_to_many,
16-
].to_set #: custom_associations
14+
].to_set #: Set[Symbol]
1715

1816
#: (
1917
#| inflector: singleton(ActiveSupport::Inflector),
20-
#| ?custom_associations: custom_associations,
18+
#| ?custom_associations: Set[Symbol],
2119
#| ?excluded_files: Set[String]
2220
#| ) -> void
2321
def initialize(inflector:, custom_associations: Set.new, excluded_files: Set.new)
2422
@inflector = inflector
25-
@associations = RAILS_ASSOCIATIONS + custom_associations #: custom_associations
23+
@associations = RAILS_ASSOCIATIONS + custom_associations #: Set[Symbol]
2624
@excluded_files = excluded_files #: Set[String]
2725
end
2826

lib/packwerk/run_context.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def from_configuration(configuration)
1414
load_paths: configuration.load_paths,
1515
package_paths: configuration.package_paths,
1616
inflector: ActiveSupport::Inflector,
17-
custom_associations: configuration.custom_associations,
17+
custom_associations: configuration.custom_associations.to_set,
1818
associations_exclude: configuration.associations_exclude,
1919
exclude: configuration.exclude,
2020
cache_enabled: configuration.cache_enabled?,
@@ -31,7 +31,7 @@ def from_configuration(configuration)
3131
#| cache_directory: Pathname,
3232
#| ?config_path: String?,
3333
#| ?package_paths: (Array[String] | String)?,
34-
#| ?custom_associations: AssociationInspector::custom_associations,
34+
#| ?custom_associations: Set[Symbol],
3535
#| ?associations_exclude: Array[String],
3636
#| ?exclude: Array[String],
3737
#| ?checkers: Array[Checker],
@@ -44,7 +44,7 @@ def initialize(
4444
cache_directory:,
4545
config_path: nil,
4646
package_paths: nil,
47-
custom_associations: [],
47+
custom_associations: Set.new,
4848
associations_exclude: [],
4949
exclude: [],
5050
checkers: Checker.all,

test/unit/packwerk/association_inspector_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class AssociationInspectorTest < Minitest::Test
1212

1313
test "#association? understands custom associations" do
1414
node = parse("has_lots :order")
15-
inspector = AssociationInspector.new(inflector: @inflector, custom_associations: [:has_lots])
15+
inspector = AssociationInspector.new(inflector: @inflector, custom_associations: Set.new([:has_lots]))
1616

1717
assert_equal "Order", inspector.constant_name_from_node(node, ancestors: [], relative_file: "")
1818
end

0 commit comments

Comments
 (0)