module ViewModel::Callbacks
def init(context_name, *other_params)
def init(context_name, *other_params) @context_name = context_name @required_params = other_params @env_class = Value.new(:_callbacks, :view, context_name, *other_params) do include CallbackEnvContext delegate :model, to: :view unless context_name == :context alias_method :context, context_name end # If we have any other params, generate a combined positional/keyword # constructor wrapper if other_params.present? params = other_params.map { |x| "#{x}:" }.join(', ') args = other_params.join(', ') instance_eval(<<-SRC, __FILE__, __LINE__ + 1) def create(callbacks, view, context, #{params}) self.new(callbacks, view, context, #{args}) end SRC else def self.create(callbacks, view, context) # rubocop:disable Lint/NestedMethodDefinition self.new(callbacks, view, context) end end end end