Dear Russian friends, please watch President Zelenskyy's speech addressed to you. πŸ‡ΊπŸ‡¦Help our brave mates in Ukraine with a donation.

Container Version

Instead of extending a class with the Dry::Initializer, you can include a container with the initializer method only. This method should be preferred when you don't need subclassing.

require 'dry-initializer'

class User
  # notice `-> do .. end` syntax
  include Dry::Initializer.define -> do
    param  :name,  proc(&:to_s)
    param  :role,  default: proc { 'customer' }
    option :admin, default: proc { false }

If you still need the DSL (param and option) to be inherited, use the direct extension:

require 'dry-initializer'

class BaseService
  extend Dry::Initializer
  alias_method :dependency, :param

class ShowUser < BaseService
  dependency :user

  def call
    puts user&.name

octocatEdit on GitHub