Sha256: 558e4e7e6b7e98fdf19a0fc20f65f871d1b5d3500e0dafa7a63b62b71247237e

Contents?: true

Size: 724 Bytes

Versions: 16

Compression:

Stored size: 724 Bytes

Contents

# frozen_string_literal: true

module Motor
  class ApiConfig < ::Motor::ApplicationRecord
    encrypts :credentials if defined?(::Motor::EncryptedConfig)

    attribute :preferences, default: -> { HashWithIndifferentAccess.new }
    attribute :credentials, default: -> { HashWithIndifferentAccess.new }

    serialize :credentials, Motor::HashSerializer
    serialize :preferences, Motor::HashSerializer

    has_one :form, dependent: nil, foreign_key: :api_config_name, primary_key: :name, inverse_of: :api_config

    scope :active, -> { where(deleted_at: nil) }

    def headers
      credentials.fetch(:headers, []).each_with_object({}) do |item, acc|
        acc[item[:key]] = item[:value]
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
motor-admin-0.4.3 app/models/motor/api_config.rb
motor-admin-0.4.2 app/models/motor/api_config.rb
motor-admin-0.4.0 app/models/motor/api_config.rb
motor-admin-0.3.17 app/models/motor/api_config.rb
motor-admin-0.3.16 app/models/motor/api_config.rb
motor-admin-0.3.15 app/models/motor/api_config.rb
mafia-admin-0.3.18 app/models/motor/api_config.rb
mafia-admin-0.3.17 app/models/motor/api_config.rb
mafia-admin-0.3.16 app/models/motor/api_config.rb
mafia-admin-0.3.15 app/models/motor/api_config.rb
mafia-admin-0.3.14 app/models/motor/api_config.rb
motor-admin-0.3.14 app/models/motor/api_config.rb
motor-admin-0.3.13 app/models/motor/api_config.rb
motor-admin-0.3.12 app/models/motor/api_config.rb
motor-admin-0.3.11 app/models/motor/api_config.rb
motor-admin-0.3.10 app/models/motor/api_config.rb