Skip to content

Conversation

@sobakasu
Copy link
Contributor

@sobakasu sobakasu commented Jan 27, 2026

Some of our projects (glg, gus, nfsa-pro) use Collections::Base with inheritance. They define an 'ApplicationCollection' with common settings and then inherit from that. Example code:

class ApplicationCollection < Katalyst::Tables::Collection::Base
  config.paginate = {}
end

class SomeController
  class Collection < ApplicationCollection
    # controller specific settings
  end
end

The expectation being that config in ApplicationCollection is inherited by SomeController::Collection. That doesn't seem to happen, as we use a class variable @config which is not inherited. This PR changes @config to a class_attribute, and dups it for subclasses. And added some tests.

@sobakasu sobakasu requested a review from sfnelson January 27, 2026 01:47
Copy link
Contributor

@sfnelson sfnelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes sense but it's a response to a wider deprecation of ActiveSupport::Configurable in Rails 8.1. I took a 'light' approach in this plus the other gems like content and koi, rather than the much more complex approach Rails took internally. Is this approach consistent with how Rails has tackled the deprecation?


spec.require_paths = ["lib"]

spec.add_dependency "activesupport"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also require activemodel. I think it's ok to assume Rails for this project and not add it to the gem spec.

@config ||= Config.new
def inherited(subclass)
super
subclass.config = config.dup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rails takes a similar but different approach that might be clearer: rails/rails@1719d25

class_attribute :config, instance_predicate: false, default: ActiveSupport::OrderedOptions.new

class_methods do
  def inherited(klass)
      klass.config = ActiveSupport::InheritableOptions.new(config)
      super
    end
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ActiveSupport::InheritableOptions looks like it's designed to work with hashes, or OrderedOptions (which extends Hash). We are using Base::Config class for config. We could stick with .dup, or update config to use OrderedOptions (but then we'd be accepting any attribute rather than just paginate and sorting)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant the new approach, vs dup, and calling it before super

@sobakasu sobakasu force-pushed the feature/core-config-class-attribute branch from 3905c9b to 78f4f4a Compare January 27, 2026 23:01
@sobakasu sobakasu force-pushed the feature/core-config-class-attribute branch from 78f4f4a to 6a27476 Compare January 27, 2026 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants