Class: LdapQuery::RailsCredentials

Inherits:
Object
  • Object
show all
Defined in:
lib/ldap_query/rails_credentials.rb

Overview

If used with a rails application, this allows the the script to pull ldap credentials from Rails.application.credentials

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#credentialsObject

Returns the value of attribute credentials.



6
7
8
# File 'lib/ldap_query/rails_credentials.rb', line 6

def credentials
  @credentials
end

Class Method Details

.credentialsHash

Used to grab the applications encrypted credentials with the ldap key

Returns:

  • (Hash)


11
12
13
14
15
16
17
18
# File 'lib/ldap_query/rails_credentials.rb', line 11

def self.credentials
  return EMPTY_HASH unless rails?

  @_credentials ||= Rails.application.credentials[:ldap]
rescue
  # In case an older rails application is used were `Rails.application.credentials` isn't defined
  raise(CredentialsError, 'Rails.application.credentials could not be found')
end

.rails?Boolean

Used to verify ‘Rails.application` exists within the codebase

Returns:

  • (Boolean)


23
24
25
# File 'lib/ldap_query/rails_credentials.rb', line 23

def self.rails?
  (defined?(Rails) && Rails.respond_to?(:application))
end