Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warnings: Use alias_method > alias_attribute for non-attributes #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jon-sully
Copy link
Collaborator

Eliminate nags!

Fixes #43

Copy link

codecov bot commented Dec 21, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.68%. Comparing base (3f41563) to head (ae31ce5).

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #45   +/-   ##
=======================================
  Coverage   98.68%   98.68%           
=======================================
  Files         102      102           
  Lines        2664     2664           
=======================================
  Hits         2629     2629           
  Misses         35       35           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jon-sully jon-sully requested a review from joshmn December 21, 2023 15:17
@jon-sully
Copy link
Collaborator Author

This one's ready. No functional change at all, just swapping a method for a Rails 7.2 compatibility

@jon-sully
Copy link
Collaborator Author

@joshmn any chance you could take a peek at this one?

@cloke
Copy link

cloke commented Sep 10, 2024

Any chance of getting this merged in? With rails 7.2 being officially released this is a blocker for sure.

@jon-sully
Copy link
Collaborator Author

All, I've reached out to @joshmn a couple of times... if he remains unavailable for another week or two, I will (sadly) fork this project and keep it up to date. I'm not sure exactly why he's been MIA lately. This gem should never block Rails upgrades.

@jon-sully
Copy link
Collaborator Author

Welp, figured that out.

https://www.yahoo.com/tech/man-ran-website-illegally-streamed-214600421.html?guccounter=1

Guess a fork is on the way.

@jon-sully
Copy link
Collaborator Author

For folks that are watching and/or find this issue, I've been pretty busy in life so I haven't had time to spin up a proper fork and try to wrestle all the side-effects that come with that. For now, I offer a monkey-patch. I've stuffed this code into my ~/config/initializers/caffeinate.rb, just under my Caffeinate.setup block:

require_dependency 'caffeinate/application_record'
require_dependency 'caffeinate/campaign_subscription'
require_dependency 'caffeinate/mailing'

Caffeinate::CampaignSubscription.class_eval do
  # Define caffeinate_campaign as a virtual attribute
  attribute :caffeinate_campaign, :string # Use the appropriate type if it's not a string

  # Alias campaign to caffeinate_campaign
  alias_method :campaign, :caffeinate_campaign
end

Caffeinate::Mailing.class_eval do
  # Define caffeinate_campaign_subscription as a virtual attribute
  attribute :caffeinate_campaign_subscription, :string # Use the appropriate type if it's not a string
  attribute :caffeinate_campaign, :string # Use the appropriate type if it's not a string

  # Alias subscription to caffeinate_campaign_subscription
  alias_method :subscription, :caffeinate_campaign_subscription
  alias_method :campaign, :caffeinate_campaign
end

This matches the three places I resolved in this PR and sets up a virtual attribute (which will immediately get overridden by ActiveRecord) to prevent the Rails 8 error from occurring, then an alias_method (proper) to stick with current style.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants