Class: TitechPubnetAuth::Config

Inherits:
Object
  • Object
show all
Includes:
Virtus::Model
Defined in:
lib/titech_pubnet_auth/config.rb

Constant Summary collapse

SERVICE_NAME =
'titech-pubnet-auth'
CONFIG_PATH =
Pathname(__FILE__) + '../../../config/private.yml'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.getObject



14
15
16
17
# File 'lib/titech_pubnet_auth/config.rb', line 14

def self.get
  key = keychain_item
  key && new(username: key., password: key.password)
end

.keychain_itemObject



19
20
21
# File 'lib/titech_pubnet_auth/config.rb', line 19

def self.keychain_item
  Keychain.generic_passwords.where(service: SERVICE_NAME).first
end

Instance Method Details

#save!Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/titech_pubnet_auth/config.rb', line 23

def save!
  key = self.class.keychain_item
  if key
    key. = username
    key.password = password
    key.save!
  else
    Keychain.generic_passwords.create(service: SERVICE_NAME, account: username, password: password)
  end
  self
end