Class: Interdependence::Types::OptionsCoercer

Inherits:
Object
  • Object
show all
Defined in:
lib/interdependence/types.rb

Overview

Coerce arguments into either a Hash or UnsetOptions

Class Method Summary collapse

Class Method Details

.call(value) ⇒ Hash, UnsetOptions

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Coerce different option values

  • Coercions:

    • true -> {}

    • nil -> UnsetOptions

    • any hash -> no change

Parameters:

  • value (input value)

Returns:



152
153
154
155
156
157
158
# File 'lib/interdependence/types.rb', line 152

def self.call(value)
  case value
  when TrueClass    then {}
  when Hash         then value
  when nil          then UnsetOptions.new
  end
end

.success?(_, value) ⇒ TrueClass, FalseClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Determine if value is a hash or unset

Parameters:

  • value (coerced value)

Returns:

  • (TrueClass, FalseClass)
    outcome


168
169
170
# File 'lib/interdependence/types.rb', line 168

def self.success?(_, value)
  value.instance_of?(Hash) || value.unset?
end