Skip to content

Conversation

@PikachuEXE
Copy link

My project uses "concern module pattern"

e.g. multiple controller classes including concern modules with instance methods cached

I am switching from memoist since it's officially unmaintained

@PikachuEXE PikachuEXE requested a review from solnic as a code owner October 8, 2021 07:20
@PikachuEXE PikachuEXE force-pushed the fix/indirect-include-setup branch from 94f017a to 6d849ad Compare October 22, 2021 07:40
@flash-gordon
Copy link
Member

Excuse my ignorance but what is "concern module pattern"? :) Why is this patch needed? At first glance, I don't feel comfortable with having a workaround for a misused ruby API.

@PikachuEXE
Copy link
Author

PikachuEXE commented Oct 23, 2021

A brief example:

require "dry/core/memoizable"

module WithBotDetection
  include Dry::Core::Memoizable

  def self.included(base)
    # Do something custom
  end

  def is_bot?(something = false)
    # ...
  end
  memoize :is_bot?
end

class Controller1
  include WithBotDetection
end

class Controller2
  include WithBotDetection
end

Controller1.new.is_bot? # => NoMethodError: undefined method `key?' for nil:NilClass

Due to #61 only happens to methods with arguments

More about "concern module pattern":
https://api.rubyonrails.org/classes/ActiveSupport/Concern.html

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.

2 participants