Class: Imap::Backup::Configuration::Store
- Inherits:
-
Object
- Object
- Imap::Backup::Configuration::Store
- Defined in:
- lib/imap/backup/configuration/store.rb
Constant Summary collapse
- CONFIGURATION_DIRECTORY =
File.("~/.imap-backup")
Instance Attribute Summary collapse
-
#pathname ⇒ Object
readonly
Returns the value of attribute pathname.
Class Method Summary collapse
Instance Method Summary collapse
- #accounts ⇒ Object
- #debug=(value) ⇒ Object
- #debug? ⇒ Boolean
-
#initialize(pathname = self.class.default_pathname) ⇒ Store
constructor
A new instance of Store.
- #modified? ⇒ Boolean
- #path ⇒ Object
- #save ⇒ Object
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
#pathname ⇒ Object (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_pathname ⇒ Object
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
#accounts ⇒ Object
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 |
#path ⇒ Object
23 24 25 |
# File 'lib/imap/backup/configuration/store.rb', line 23 def path File.dirname(pathname) end |
#save ⇒ Object
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 |