Class: Hector::YamlIdentityAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/hector/yaml_identity_adapter.rb

Overview

Identity adapters must implement the following public methods:

- authenticate(username, password)
- remember(username, password)
- forget(username)
- normalize(username)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ YamlIdentityAdapter

Returns a new instance of YamlIdentityAdapter.



11
12
13
# File 'lib/hector/yaml_identity_adapter.rb', line 11

def initialize(filename)
  @filename = File.expand_path(filename)
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



9
10
11
# File 'lib/hector/yaml_identity_adapter.rb', line 9

def filename
  @filename
end

Instance Method Details

#authenticate(username, password) {|load_identities[normalize(username)] == hash(normalize(username), password)| ... } ⇒ Object

Yields:



15
16
17
# File 'lib/hector/yaml_identity_adapter.rb', line 15

def authenticate(username, password)
  yield load_identities[normalize(username)] == hash(normalize(username), password)
end

#forget(username) ⇒ Object



25
26
27
28
29
# File 'lib/hector/yaml_identity_adapter.rb', line 25

def forget(username)
  identities = load_identities
  identities.delete(normalize(username))
  store_identities(identities)
end

#normalize(username) ⇒ Object



31
32
33
# File 'lib/hector/yaml_identity_adapter.rb', line 31

def normalize(username)
  username.strip.downcase
end

#remember(username, password) ⇒ Object



19
20
21
22
23
# File 'lib/hector/yaml_identity_adapter.rb', line 19

def remember(username, password)
  identities = load_identities
  identities[normalize(username)] = hash(normalize(username), password)
  store_identities(identities)
end