Sha256: 6e9a93013a3cd49863593b1e4b7974e220c4f8a16043070e9dc2ae5a99393871

Contents?: true

Size: 724 Bytes

Versions: 51

Compression:

Stored size: 724 Bytes

Contents

# frozen_string_literal: true

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

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

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

    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

51 entries across 51 versions & 1 rubygems

Version Path
motor-admin-0.3.9 app/models/motor/api_config.rb
motor-admin-0.3.8 app/models/motor/api_config.rb
motor-admin-0.3.7 app/models/motor/api_config.rb
motor-admin-0.3.6 app/models/motor/api_config.rb
motor-admin-0.3.5 app/models/motor/api_config.rb
motor-admin-0.3.4 app/models/motor/api_config.rb
motor-admin-0.3.3 app/models/motor/api_config.rb
motor-admin-0.3.2 app/models/motor/api_config.rb
motor-admin-0.3.1 app/models/motor/api_config.rb
motor-admin-0.3.0 app/models/motor/api_config.rb
motor-admin-0.2.89 app/models/motor/api_config.rb
motor-admin-0.2.88 app/models/motor/api_config.rb
motor-admin-0.2.87 app/models/motor/api_config.rb
motor-admin-0.2.86 app/models/motor/api_config.rb
motor-admin-0.2.85 app/models/motor/api_config.rb
motor-admin-0.2.84 app/models/motor/api_config.rb
motor-admin-0.2.83 app/models/motor/api_config.rb
motor-admin-0.2.82 app/models/motor/api_config.rb
motor-admin-0.2.81 app/models/motor/api_config.rb
motor-admin-0.2.80 app/models/motor/api_config.rb