Class: ActiveInteractor::Type::Union

Inherits:
Base
  • Object
show all
Defined in:
lib/active_interactor/type/union.rb

Instance Method Summary collapse

Methods inherited from Base

valid?

Constructor Details

#initialize(*types) ⇒ Union

rubocop:disable Lint/MissingSuper



6
7
8
# File 'lib/active_interactor/type/union.rb', line 6

def initialize(*types) # rubocop:disable Lint/MissingSuper
  @valid_types = types
end

Instance Method Details

#valid?(value) ⇒ Boolean

Returns:



10
11
12
13
14
15
16
# File 'lib/active_interactor/type/union.rb', line 10

def valid?(value)
  return true if value.nil?

  @valid_types.any? do |type|
    value_is_a_valid_active_interactor_type?(type, value) || value.is_a?(type)
  end
end