Class: GMail::Index
- Inherits:
-
Object
- Object
- GMail::Index
- Defined in:
- lib/gmail/index.rb
Overview
Manages a database of message-ids from mail converted from gmvault into Maildir
Instance Attribute Summary (collapse)
-
- (Object) db
readonly
Returns the value of attribute db.
-
- (Object) path
readonly
Returns the value of attribute path.
Instance Method Summary (collapse)
-
- (TrueClass|FalseClass) [](gm_id)
Allow getting a value.
-
- (Object) []=(gm_id, value)
Allow inserting a new value.
-
- (Object) check_db
Check db version and upgrade it if needed.
-
- (String) gmdb
Returns the path to the gmvault db.
-
- (Object) gmdb=(value)
Set the gmvault db path in the index.
-
- (Index) initialize(path)
constructor
Create a new index if the file is not present or open the current one.
-
- (String) last_id
Return the last_id from the db.
-
- (Object) last_id=(value)
Set the last_id property in the db.
-
- (Time) last_sync
Return the time of the last sync through the 'last_sync' property.
-
- (Object) last_sync=(value)
Set the last_sync property in the db.
-
- (TrueClass|FalseClass) present?(gm_id)
Check if a given gm_id is present.
-
- (Fixnum) size
Returns the size of the db.
-
- (Fixnum) version
Returns the db version.
Constructor Details
- (Index) initialize(path)
Create a new index if the file is not present or open the current one.
18 19 20 21 22 23 24 25 26 |
# File 'lib/gmail/index.rb', line 18 def initialize(path) if File.exists?("#{path}/cur") and File.exists?("#{path}/new") @path = path else raise ArgumentError, "#{path} is not a Maildir mailbox" end @db = Rufus::Tokyo::Cabinet.new("#{path}/index.tch") check_db() end |
Instance Attribute Details
- (Object) db (readonly)
Returns the value of attribute db
14 15 16 |
# File 'lib/gmail/index.rb', line 14 def db @db end |
- (Object) path (readonly)
Returns the value of attribute path
14 15 16 |
# File 'lib/gmail/index.rb', line 14 def path @path end |
Instance Method Details
- (TrueClass|FalseClass) [](gm_id)
Allow getting a value
53 54 55 56 57 58 |
# File 'lib/gmail/index.rb', line 53 def [](gm_id) if gm_id.nil? return(gm_id) end @db[gm_id] end |
- (Object) []=(gm_id, value)
Allow inserting a new value
63 64 65 66 |
# File 'lib/gmail/index.rb', line 63 def []=(gm_id, value) return nil if gm_id.nil? @db[gm_id] = value end |
- (Object) check_db
Check db version and upgrade it if needed
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gmail/index.rb', line 29 def check_db if @db['db_version'].nil? @db['db_version'] = GMail::Utils::DB_VERSION end if @db['gmdb'].nil? puts('Warning: gmdb not found...') end if @db['db_version'] == '2' @db['last_sync'] = Time.now @db['db_version'] = '3' end end |
- (String) gmdb
Returns the path to the gmvault db
100 101 102 |
# File 'lib/gmail/index.rb', line 100 def gmdb @db['gmdb'] end |
- (Object) gmdb=(value)
Set the gmvault db path in the index
106 107 108 |
# File 'lib/gmail/index.rb', line 106 def gmdb=(value) @db['gmdb'] = value || '' end |
- (String) last_id
Return the last_id from the db
70 71 72 |
# File 'lib/gmail/index.rb', line 70 def last_id @db['last_id'] end |
- (Object) last_id=(value)
Set the last_id property in the db
76 77 78 |
# File 'lib/gmail/index.rb', line 76 def last_id=(value) @db['last_id'] = value end |
- (Time) last_sync
Return the time of the last sync through the 'last_sync' property
82 83 84 |
# File 'lib/gmail/index.rb', line 82 def last_sync @db['last_sync'] end |
- (Object) last_sync=(value)
Set the last_sync property in the db
88 89 90 |
# File 'lib/gmail/index.rb', line 88 def last_sync=(value) @db['last_sync'] = value end |
- (TrueClass|FalseClass) present?(gm_id)
Check if a given gm_id is present
45 46 47 48 |
# File 'lib/gmail/index.rb', line 45 def present?(gm_id) return false if gm_id.nil? return @db.keys.include?(gm_id) end |
- (Fixnum) size
Returns the size of the db
94 95 96 |
# File 'lib/gmail/index.rb', line 94 def size @db.size end |
- (Fixnum) version
Returns the db version
112 113 114 |
# File 'lib/gmail/index.rb', line 112 def version @db['db_version'].to_i || 0 end |