Sha256: afc8d882631f2ea2e7020188f442ae50f56f6a960a54476fc363cc3ba283611d

Contents?: true

Size: 716 Bytes

Versions: 7

Compression:

Stored size: 716 Bytes

Contents

# frozen_string_literal: true

module CoinsPaid
  class Address
    module Types
      include Dry.Types()
    end

    class Data < Dry::Struct
      attribute :foreign_id, Types::Coercible::String
      attribute :currency, Types::String
      attribute :convert_to, Types::String
    end

    include Dry::Initializer.define -> do
      param :request_data, Data
    end

    def call
      ActiveRecord::Base.transaction do
        CoinsPaidAddress.lock.find_or_create_by!(request_data.attributes.slice(:foreign_id, :currency)) do |address|
          response = CoinsPaid::API.take_address(request_data.attributes)
          address.assign_attributes(response.attributes)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
coins_paid_rails-1.2.0 lib/coins_paid/address.rb
coins_paid_rails-1.1.8 lib/coins_paid/address.rb
coins_paid_rails-1.1.7 lib/coins_paid/address.rb
coins_paid_rails-1.1.6 lib/coins_paid/address.rb
coins_paid_rails-1.1.4 lib/coins_paid/address.rb
coins_paid_rails-1.1.3 lib/coins_paid/address.rb
coins_paid_rails-1.1.2 lib/coins_paid/address.rb