Sha256: f0e67c88ce8d13c029dd5decdc78cf680e32a105f7e8ee4a460c02fa5999d96d

Contents?: true

Size: 607 Bytes

Versions: 4

Compression:

Stored size: 607 Bytes

Contents

module Spyke
  class Attributes < HashWithIndifferentAccess
    def to_params
      each_with_object({}) do |(key, value), parameters|
        parameters[key] = parse_value(value)
      end.with_indifferent_access
    end

    private

      def parse_value(value)
        case
        when value.is_a?(Spyke::Base)         then value.attributes.to_params
        when value.is_a?(Array)               then value.map { |v| parse_value(v) }
        when value.respond_to?(:content_type) then Faraday::Multipart::FilePart.new(value.path, value.content_type)
        else value
        end
      end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spyke-7.2.2 lib/spyke/attributes.rb
spyke-7.1.1 lib/spyke/attributes.rb
spyke-7.1.0 lib/spyke/attributes.rb
spyke-7.0.0 lib/spyke/attributes.rb