Class: RailsApiKeys::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_api_keys/configuration.rb

Overview

Optional host overrides. Set via configure.

Defaults: token_prefix derives from the app name, and owner_active uses Devise-style active_for_authentication? when available. Owner models opt in with Owner.has_api_keys.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



12
13
14
15
16
17
18
19
20
21
# File 'lib/rails_api_keys/configuration.rb', line 12

def initialize
  @token_prefix = nil
  @owner_active = ->(owner) {
    if owner.respond_to?(:active_for_authentication?)
      owner.active_for_authentication?
    else
      true
    end
  }
end

Instance Attribute Details

#owner_activeObject

Returns the value of attribute owner_active.



10
11
12
# File 'lib/rails_api_keys/configuration.rb', line 10

def owner_active
  @owner_active
end

#token_prefixObject

Returns the value of attribute token_prefix.



10
11
12
# File 'lib/rails_api_keys/configuration.rb', line 10

def token_prefix
  @token_prefix
end

Instance Method Details

#owner_active?(owner) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/rails_api_keys/configuration.rb', line 29

def owner_active?(owner)
  owner_active.call(owner)
end

#resolved_token_prefixObject



23
24
25
26
27
# File 'lib/rails_api_keys/configuration.rb', line 23

def resolved_token_prefix
  return token_prefix.to_s if token_prefix.present?

  "#{Rails.application.class.module_parent_name.downcase}_ak_"
end