lib/simple_jsonapi/helpers/serializer_methods.rb
def with(**data)
    ivar_data = data.transform_keys { |key| :"@#{key}" }

    existing_keys = ivar_data.each_key.select { |key| instance_variable_defined?(key) }
    if existing_keys.any?
      raise ArgumentError, "Cannot override existing instance variables #{existing_keys.to_sentence}."
    end

    begin
      ivar_data.each { |k, v| instance_variable_set(k, v) }
      yield
    ensure
      ivar_data.each_key { |k| remove_instance_variable(k) }
    end
  end
# Adds the provided data values to the serializer as instance variables for the duration of the block.
# @param data [Hash{Symbol => Object}]
Adds the provided data values to the serializer as instance variables for the duration of the block.
Adds the provided data values to the serializer as instance variables for the duration of the block .
def with(**data)
    ivar_data = data.transform_keys { |key| :"@#{key}" }
    existing_keys = ivar_data.each_key.select { |key| instance_variable_defined?(key) }
    if existing_keys.any?
      raise ArgumentError, "Cannot override existing instance variables #{existing_keys.to_sentence}."
    end
    begin
      ivar_data.each { |k, v| instance_variable_set(k, v) }
      yield
    ensure
      ivar_data.each_key { |k| remove_instance_variable(k) }
    end
  end
def with ( ** data ) ivar_data = data . transform_keys { | key | :" @ #{ key } " } existing_keys = ivar_data . each_key . select { | key | instance_variable_defined? ( key ) } if existing_keys . any? raise ArgumentError , "Cannot override existing instance variables #{existing_keys.to_sentence}." end begin ivar_data . each { | k , v | instance_variable_set ( k , v ) } yield ensure ivar_data . each_key { | k | remove_instance_variable ( k ) } end end
Adds the provided data values to the serializer as instance variables for the duration of the block.
Adds the provided data values to the serializer as instance variables for the duration of the block .
data
None