Class: Imap::Backup::Configuration::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/imap/backup/configuration/store.rb

Constant Summary collapse

CONFIGURATION_DIRECTORY =
File.expand_path("~/.imap-backup")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pathname = self.class.default_pathname) ⇒ Store



19
20
21
# File 'lib/imap/backup/configuration/store.rb', line 19

def initialize(pathname = self.class.default_pathname)
  @pathname = pathname
end

Instance Attribute Details

#pathnameObject (readonly)

Returns the value of attribute pathname.



9
10
11
# File 'lib/imap/backup/configuration/store.rb', line 9

def pathname
  @pathname
end

Class Method Details

.default_pathnameObject



11
12
13
# File 'lib/imap/backup/configuration/store.rb', line 11

def self.default_pathname
  File.join(CONFIGURATION_DIRECTORY, "config.json")
end

.exist?(pathname = default_pathname) ⇒ Boolean



15
16
17
# File 'lib/imap/backup/configuration/store.rb', line 15

def self.exist?(pathname = default_pathname)
  File.exist?(pathname)
end

Instance Method Details

#accountsObject



35
36
37
# File 'lib/imap/backup/configuration/store.rb', line 35

def accounts
  data[:accounts]
end

#debug=(value) ⇒ Object



47
48
49
# File 'lib/imap/backup/configuration/store.rb', line 47

def debug=(value)
  data[:debug] = [true, false].include?(value) ? value : false
end

#debug?Boolean



43
44
45
# File 'lib/imap/backup/configuration/store.rb', line 43

def debug?
  data[:debug]
end

#modified?Boolean



39
40
41
# File 'lib/imap/backup/configuration/store.rb', line 39

def modified?
  accounts.any? { |a| a[:modified] || a[:delete] }
end

#pathObject



23
24
25
# File 'lib/imap/backup/configuration/store.rb', line 23

def path
  File.dirname(pathname)
end

#saveObject



27
28
29
30
31
32
33
# File 'lib/imap/backup/configuration/store.rb', line 27

def save
  mkdir_private path
  remove_modified_flags
  remove_deleted_accounts
  File.open(pathname, "w") { |f| f.write(JSON.pretty_generate(data)) }
  FileUtils.chmod 0o600, pathname
end