Sha256: 39821321061e19971c4a2d4bee3ffa133f107fc0ef235e08688fdddffa513d36

Contents?: true

Size: 596 Bytes

Versions: 46

Compression:

Stored size: 596 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::UploadIO.new(value.path, value.content_type)
        else value
        end
      end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
spyke-6.1.3 lib/spyke/attributes.rb
spyke-6.1.2 lib/spyke/attributes.rb
spyke-6.1.1 lib/spyke/attributes.rb
spyke-6.1.0 lib/spyke/attributes.rb
spyke-6.0.0 lib/spyke/attributes.rb
spyke-5.4.3 lib/spyke/attributes.rb
spyke-5.4.2 lib/spyke/attributes.rb
spyke-5.4.1 lib/spyke/attributes.rb
spyke-5.4.0 lib/spyke/attributes.rb
spyke-5.3.4 lib/spyke/attributes.rb
spyke-5.3.3 lib/spyke/attributes.rb
spyke-5.3.2 lib/spyke/attributes.rb
spyke-5.3.1 lib/spyke/attributes.rb
spyke-5.3.0 lib/spyke/attributes.rb
spyke-5.2.0 lib/spyke/attributes.rb
spyke-5.1.0 lib/spyke/attributes.rb
spyke-5.0.0 lib/spyke/attributes.rb
spyke-4.1.1 lib/spyke/attributes.rb
spyke-4.1.0 lib/spyke/attributes.rb
spyke-4.0.1 lib/spyke/attributes.rb