Skip to content

Conversation

kwasniew
Copy link
Contributor

@kwasniew kwasniew commented Aug 19, 2025

About the changes

Changes:

  • Extract shared backup functionality - Moved file saving logic from ToggleFetcher to new BackupFileWriter class for reuse between polling and streaming modes

Important files

Discussion points

require 'unleash/configuration'

module Unleash
class BackupFileWriter
Copy link
Contributor Author

Choose a reason for hiding this comment

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

extracted from toggle_fetcher so that we can share it between polling and streaming

Copy link
Collaborator

Choose a reason for hiding this comment

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

Bikeshedding: This might be better served / mode idiomatic by using MixIns in Ruby.

Here is an example:

https://blog.appsignal.com/2021/01/13/using-mixins-and-modules-in-your-ruby-on-rails-application.html

or

Using include with Modules (Mixins):
The include keyword is used to add a module's methods as instance methods to a class. This is a common way to achieve "mixin" behavior, sharing functionality across unrelated classes.

module Greetable
  def greet_instance
    puts "Hello from the instance!"
  end
end

class MyOtherClass
  include Greetable # Adds greet_instance as an instance method
end

my_instance = MyOtherClass.new
my_instance.greet_instance # Output: Hello from the instance!

Copy link
Contributor Author

@kwasniew kwasniew Aug 20, 2025

Choose a reason for hiding this comment

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

Questions I asked myself:

  • do I need to access object state from a mixin method?
  • do I want save file operation in fetcher API and streaming processor API?
  • is toggle fetcher and streaming event processor a backup file writer (IS-A) or does it use (HAS-A) a backup file writer?
  • is this code readable for somone maintaining 5 other SDKs on a daily basis?

It lead me to the current solution.

Copy link
Member

Choose a reason for hiding this comment

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

is this code readable for somone maintaining 5 other SDKs on a daily basis

❤️

I think this solution is fine honestly. If I were going to fuss, it'd be in the direction of making this explicitly stateless rather than the tacit connection that a MixIn brings here. I vote we leave it alone, I think it's a nice improvement to the code structure

Copy link
Collaborator

Choose a reason for hiding this comment

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

Your points make sense! Go for it!

@FredrikOseberg FredrikOseberg moved this from New to In Progress in Issues and PRs Aug 20, 2025
@kwasniew kwasniew requested a review from sighphyre August 20, 2025 07:35
Copy link
Member

@sighphyre sighphyre left a comment

Choose a reason for hiding this comment

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

Awesome, thank you!

require 'unleash/configuration'

module Unleash
class BackupFileWriter
Copy link
Member

Choose a reason for hiding this comment

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

is this code readable for somone maintaining 5 other SDKs on a daily basis

❤️

I think this solution is fine honestly. If I were going to fuss, it'd be in the direction of making this explicitly stateless rather than the tacit connection that a MixIn brings here. I vote we leave it alone, I think it's a nice improvement to the code structure

@github-project-automation github-project-automation bot moved this from In Progress to Approved PRs in Issues and PRs Aug 20, 2025
@kwasniew kwasniew merged commit 4184c8c into main Aug 20, 2025
79 of 110 checks passed
@kwasniew kwasniew deleted the save-backup-file branch August 20, 2025 08:33
@github-project-automation github-project-automation bot moved this from Approved PRs to Done in Issues and PRs Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants