lib/hanami/interactor.rb in hanami-utils-1.3.6 vs lib/hanami/interactor.rb in hanami-utils-1.3.7
- old
+ new
@@ -1,9 +1,11 @@
-require 'hanami/utils/basic_object'
-require 'hanami/utils/class_attribute'
-require 'hanami/utils/hash'
+# frozen_string_literal: true
+require "hanami/utils/basic_object"
+require "hanami/utils/class_attribute"
+require "hanami/utils/hash"
+
module Hanami
# Hanami Interactor
#
# @since 0.3.5
module Interactor
@@ -15,18 +17,18 @@
#
# @since 0.3.5
# @api private
#
# @see Hanami::Interactor::Result#respond_to_missing?
- METHODS = ::Hash[initialize: true,
- success?: true,
+ METHODS = ::Hash[initialize: true,
+ success?: true,
successful?: true,
- failure?: true,
- fail!: true,
- prepare!: true,
- errors: true,
- error: true].freeze
+ failure?: true,
+ fail!: true,
+ prepare!: true,
+ errors: true,
+ error: true].freeze
# Initialize a new result
#
# @param payload [Hash] a payload to carry on
#
@@ -48,11 +50,11 @@
def successful?
@success && errors.empty?
end
# @since 0.3.5
- alias success? successful?
+ alias_method :success?, :successful?
# Checks if the current status is not successful
#
# @return [TrueClass,FalseClass] the result of the check
#
@@ -349,30 +351,54 @@
#
# # Method #call is not defined
# end
#
# Signup.new.call # => NoMethodError
- def call(*args)
- @__result = ::Hanami::Interactor::Result.new
- _call(*args) { super }
+ if RUBY_VERSION >= "3.0"
+ def call(*args, **kwargs)
+ @__result = ::Hanami::Interactor::Result.new
+ _call(*args, **kwargs) { super }
+ end
+ else
+ def call(*args)
+ @__result = ::Hanami::Interactor::Result.new
+ _call(*args) { super }
+ end
end
private
# @api private
# @since 1.1.0
- def _call(*args)
- catch :fail do
- validate!(*args)
- yield
+ if RUBY_VERSION >= "3.0"
+ def _call(*args, **kwargs)
+ catch :fail do
+ validate!(*args, **kwargs)
+ yield
+ end
+
+ _prepare!
end
+ else
+ def _call(*args)
+ catch :fail do
+ validate!(*args)
+ yield
+ end
- _prepare!
+ _prepare!
+ end
end
# @since 1.1.0
- def validate!(*args)
- fail! unless valid?(*args)
+ if RUBY_VERSION >= "3.0"
+ def validate!(*args, **kwargs)
+ fail! unless valid?(*args, **kwargs)
+ end
+ else
+ def validate!(*args)
+ fail! unless valid?(*args)
+ end
end
end
private