Class: Subledger::Domain::Key

Inherits:
Object
  • Object
show all
Includes:
Subledger::Domain, Roles::Activatable, Roles::Archivable, Roles::Attributable, Roles::Collectable, Roles::Creatable, Roles::Identifiable, Roles::Readable, Roles::Restable, Roles::Storable
Defined in:
lib/subledger/domain/key.rb

Direct Known Subclasses

ActiveKey, ArchivedKey

Defined Under Namespace

Classes: Entity

Instance Attribute Summary collapse

Attributes included from Roles::Storable

#client, #store

Attributes included from Roles::Identifiable

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Roles::Restable

#patch_hash, #post_hash, #serializable_hash, #to_json

Methods included from Roles::Archivable

#archive

Methods included from Roles::Activatable

#activate

Methods included from Roles::Collectable

included

Methods included from Roles::Readable

included, #read

Methods included from Roles::Creatable

#create, included

Methods included from Roles::Attributable

#attributes

Methods included from Subledger::Domain

#==, #collection_name, #entity_name, included, #to_s

Constructor Details

#initialize(args) ⇒ Key

Returns a new instance of Key.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/subledger/domain/key.rb', line 44

def initialize args
  identifiable args
  storable args

  @identity = args[:identity]

  # TODO separate new and create

  if args[:bcrypt].nil?
    @secret = args[:secret] || UUID.as_string

    @bcrypt = BCrypt::Password.create( @secret, :cost => 5 )
  elsif args[:bcrypt]
    @secret = args[:secret]

    @bcrypt = BCrypt::Password.new args[:bcrypt]
  end
end

Instance Attribute Details

#identityObject (readonly)

Returns the value of attribute identity.



22
23
24
# File 'lib/subledger/domain/key.rb', line 22

def identity
  @identity
end

#secretObject (readonly)

Returns the value of attribute secret.



22
23
24
# File 'lib/subledger/domain/key.rb', line 22

def secret
  @secret
end

Class Method Details

.active_klassObject



36
37
38
# File 'lib/subledger/domain/key.rb', line 36

def self.active_klass
  ActiveKey
end

.archived_klassObject



40
41
42
# File 'lib/subledger/domain/key.rb', line 40

def self.archived_klass
  ArchivedKey
end

.post_keysObject



24
25
26
# File 'lib/subledger/domain/key.rb', line 24

def self.post_keys
  [ :id, :identity ]
end

.root_klassObject



28
29
30
# File 'lib/subledger/domain/key.rb', line 28

def self.root_klass
  Key
end

.sub_klassesObject



32
33
34
# File 'lib/subledger/domain/key.rb', line 32

def self.sub_klasses
  [ archived_klass, active_klass ]
end

Instance Method Details

#authenticates?(this_secret) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/subledger/domain/key.rb', line 63

def authenticates? this_secret
  bcrypt == this_secret
end