Class: Keybox::AccountEntry

Inherits:
Storage::Record show all
Defined in:
lib/keybox/entry.rb

Overview

Entries in the Keybox storage container. The base class is AccountEntry with current child classes HostAccountEntry and URLAccountEntry.

In most cases HostAccountEntry will suffice. Use URLAccountEntry when you would like to link an entry’s password field to be generated based upon the master password of the container.

Direct Known Subclasses

HostAccountEntry, URLAccountEntry

Constant Summary

Constants inherited from Storage::Record

Storage::Record::PROTECTED_METHODS

Instance Attribute Summary

Attributes inherited from Storage::Record

#creation_time, #data_members, #last_access_time, #modification_time, #uuid

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Storage::Record

#==, #data_member_names, #eql?, #method_missing, #modified=, #modified?, #to_yaml_properties

Constructor Details

#initialize(title = "", username = "") ⇒ AccountEntry

Returns a new instance of AccountEntry.



80
81
82
83
84
85
# File 'lib/keybox/entry.rb', line 80

def initialize(title = "",username = "")
    super()
    self.title              = title
    self.username           = username
    self.additional_info    = ""
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Keybox::Storage::Record

Class Method Details

.default_fieldsObject



14
15
16
# File 'lib/keybox/entry.rb', line 14

def default_fields
    %w(title username additional_info)
end

.display_fieldsObject

fields that can be displayed, some could be calculated



19
20
21
# File 'lib/keybox/entry.rb', line 19

def display_fields
    (visible_fields + private_fields).uniq
end

.private_field?(field_name) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/keybox/entry.rb', line 35

def private_field?(field_name)
    private_fields.include?(field_name)
end

.private_fieldsObject



23
24
25
# File 'lib/keybox/entry.rb', line 23

def private_fields
    []
end

.visible_field?(field_name) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/keybox/entry.rb', line 31

def visible_field?(field_name)
    visible_fields.include?(field_name)
end

.visible_fieldsObject



27
28
29
# File 'lib/keybox/entry.rb', line 27

def visible_fields
    default_fields - private_fields
end

Instance Method Details

#default_fieldsObject



51
52
53
# File 'lib/keybox/entry.rb', line 51

def default_fields
    self.class.default_fields
end

#display_fieldsObject



55
56
57
# File 'lib/keybox/entry.rb', line 55

def display_fields
    self.class.display_fields
end

#eachObject



40
41
42
43
44
# File 'lib/keybox/entry.rb', line 40

def each
    fields.each do |f|
        yield [f,self.send(f)]
    end
end

#fieldsObject

fields that are actually stored in the entry



47
48
49
# File 'lib/keybox/entry.rb', line 47

def fields
    (default_fields + @data_members.keys ).collect { |k| k.to_s }.uniq
end

#max_field_lengthObject



106
107
108
# File 'lib/keybox/entry.rb', line 106

def max_field_length
    fields.collect { |f| f.length }.max
end

#needs_container_passphrase?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/keybox/entry.rb', line 87

def needs_container_passphrase?
    false
end

#private_field?(field_name) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/keybox/entry.rb', line 63

def private_field?(field_name)
    self.class.private_field?(field_name)
end

#private_fieldsObject



59
60
61
# File 'lib/keybox/entry.rb', line 59

def private_fields
    self.class.private_fields
end

#to_sObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/keybox/entry.rb', line 91

def to_s
    s = StringIO.new
    max_length = self.max_field_length
    fields.each do |f|
        line = "#{f.rjust(max_length + 1)} :"
        value = self.send(f)
        if private_field?(f) then
            # if its private field, then blank out value just to
            value = " ***** private ***** "
        end
        s.puts "#{f.rjust(max_length + 1)} : #{value}"
    end
    return s.string
end

#valuesObject



76
77
78
# File 'lib/keybox/entry.rb', line 76

def values
    fields.collect { |f| self.send(f) }
end

#visible_field?(field_name) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/keybox/entry.rb', line 71

def visible_field?(field_name)
    self.class.visible_field?(field_name)
end

#visible_fieldsObject



67
68
69
# File 'lib/keybox/entry.rb', line 67

def visible_fields
    self.class.visible_fields
end