Sha256: b719e26446e0503cbe50afac53db5c53b848177ef65f515788719279b9fda2fc

Contents?: true

Size: 628 Bytes

Versions: 3

Compression:

Stored size: 628 Bytes

Contents

# frozen_string_literal: true

require "active_model"

module Auther
  ACCOUNT_ATTRIBUTES = %i[
    name
    encrypted_login
    encrypted_password
    paths
    authorized_url
    deauthorized_url
  ].freeze

  # Represents an authenticatable account.
  Account = Struct.new(*ACCOUNT_ATTRIBUTES, keyword_init: true) do
    include ActiveModel::Validations

    validates :name, :encrypted_login, :encrypted_password, presence: true
    validate :paths_type

    def paths
      self[:paths] || []
    end

    private

    def paths_type
      errors.add(:paths, "must be an array") unless paths.is_a?(Array)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
auther-10.0.0 app/models/auther/account.rb
auther-9.3.0 app/models/auther/account.rb
auther-9.2.0 app/models/auther/account.rb