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
Returns a new instance of Store.
21 22 23 |
# File 'lib/imap/backup/configuration/store.rb', line 21 def initialize(pathname = self.class.default_pathname) @pathname = pathname end |
Instance Attribute Details
#pathname ⇒ Object (readonly)
Returns the value of attribute pathname.
11 12 13 |
# File 'lib/imap/backup/configuration/store.rb', line 11 def pathname @pathname end |
Class Method Details
.default_pathname ⇒ Object
13 14 15 |
# File 'lib/imap/backup/configuration/store.rb', line 13 def self.default_pathname File.join(CONFIGURATION_DIRECTORY, 'config.json') end |
.exist?(pathname = default_pathname) ⇒ Boolean
17 18 19 |
# File 'lib/imap/backup/configuration/store.rb', line 17 def self.exist?(pathname = default_pathname) File.exist?(pathname) end |
Instance Method Details
#accounts ⇒ Object
37 38 39 |
# File 'lib/imap/backup/configuration/store.rb', line 37 def accounts data[:accounts] end |
#debug=(value) ⇒ Object
49 50 51 |
# File 'lib/imap/backup/configuration/store.rb', line 49 def debug=(value) data[:debug] = [true, false].include?(value) ? value : false end |
#debug? ⇒ Boolean
45 46 47 |
# File 'lib/imap/backup/configuration/store.rb', line 45 def debug? data[:debug] end |
#modified? ⇒ Boolean
41 42 43 |
# File 'lib/imap/backup/configuration/store.rb', line 41 def modified? accounts.any? { |a| a[:modified] || a[:delete] } end |
#path ⇒ Object
25 26 27 |
# File 'lib/imap/backup/configuration/store.rb', line 25 def path File.dirname(pathname) end |
#save ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/imap/backup/configuration/store.rb', line 29 def save mkdir_private path remove_modified_flags remove_deleted_accounts File.open(pathname, 'w') { |f| f.write(JSON.pretty_generate(data)) } FileUtils.chmod 0600, pathname end |