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

Add a Readyset.configure method that allows users to configure our gem #33

Closed
ethan-readyset opened this issue Nov 22, 2023 · 1 comment · Fixed by #40
Closed

Add a Readyset.configure method that allows users to configure our gem #33

ethan-readyset opened this issue Nov 22, 2023 · 1 comment · Fixed by #40
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@ethan-readyset
Copy link
Contributor

ethan-readyset commented Nov 22, 2023

Brief Description of Feature:
We should add a Readyset.configure method that allows users to configure our gem similar to what is done here.

Background:
The typical way to configure a gem in the context of a Rails application seems to be to add a file for the gem in the config/initializers directory and then invoke GemName.configure. Readyset.configure should take a block and yield a Readyset::Configuration object to that block like so:

Readyset.configure do |config|
  config.option1 = ...
  config.option2 = ...
end

Optional information to add

Proposed Solution:
Internally, we should define Readyset.configuration and Readyset.configure methods like so:

lib/readyset.rb
module Readyset
  def self.configuration
    @configuration ||= Configuration.new
  end

  class << self
    delegate :configure, to: :configuration
  end
end

# lib/readyset/configuration.rb
module Readyset
  class Configuration
    def configure
      yield(self)
    end
  end
end

Readyset::Configuration should specify attr_accessors for any of the configuration options we'd like to support. We could also consider making Readyset::Configuration a module since it will only ever have one instance. I don't think we should mixin that module because I don't want Readyset to be overloaded with too much state, but we could do something like this:

lib/readyset.rb
module Readyset
  class << self
    delegate :configure, to: :Configuration
  end
end

# lib/readyset/configuration.rb
module Readyset
  module Configuration
    attr_accessor :option_1, ...

    @option_1 = 'option 1 default value'
    ...

    def self.configure
      yield(self)
    end
  end
end
@helpotters
Copy link
Contributor

Starting on this issue now. I'll use the gem you linked as a reference. Thank you for finding that! It's perfect.

@helpotters helpotters added the enhancement New feature or request label Dec 5, 2023
@helpotters helpotters linked a pull request Dec 5, 2023 that will close this issue
@ethan-readyset ethan-readyset changed the title Standardize our gem's configuration interface Add a Readyset.configure method that allows users to configure our gem Dec 8, 2023
@ethan-readyset ethan-readyset linked a pull request Dec 12, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
3 participants