Class: Imap::Backup::Configuration
- Inherits:
-
Object
- Object
- Imap::Backup::Configuration
- Defined in:
- lib/imap/backup/configuration.rb
Constant Summary collapse
- CONFIGURATION_DIRECTORY =
File.("~/.imap-backup")
- VERSION =
"2.0".freeze
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) ⇒ Configuration
constructor
A new instance of Configuration.
- #modified? ⇒ Boolean
- #path ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(pathname = self.class.default_pathname) ⇒ Configuration
Returns a new instance of Configuration.
21 22 23 24 25 |
# File 'lib/imap/backup/configuration.rb', line 21 def initialize(pathname = self.class.default_pathname) @pathname = pathname @saved_debug = nil @debug = nil end |
Instance Attribute Details
#pathname ⇒ Object (readonly)
Returns the value of attribute pathname.
11 12 13 |
# File 'lib/imap/backup/configuration.rb', line 11 def pathname @pathname end |
Class Method Details
.default_pathname ⇒ Object
13 14 15 |
# File 'lib/imap/backup/configuration.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.rb', line 17 def self.exist?(pathname = default_pathname) File.exist?(pathname) end |
Instance Method Details
#accounts ⇒ Object
47 48 49 50 51 52 |
# File 'lib/imap/backup/configuration.rb', line 47 def accounts @accounts ||= begin ensure_loaded! data[:accounts].map { |data| Account.new(data) } end end |
#debug=(value) ⇒ Object
66 67 68 69 |
# File 'lib/imap/backup/configuration.rb', line 66 def debug=(value) ensure_loaded! @debug = [true, false].include?(value) ? value : false end |
#debug? ⇒ Boolean
61 62 63 64 |
# File 'lib/imap/backup/configuration.rb', line 61 def debug? ensure_loaded! @debug end |
#modified? ⇒ Boolean
54 55 56 57 58 59 |
# File 'lib/imap/backup/configuration.rb', line 54 def modified? ensure_loaded! return true if @saved_debug != @debug accounts.any? { |a| a.modified? || a.marked_for_deletion? } end |
#path ⇒ Object
27 28 29 |
# File 'lib/imap/backup/configuration.rb', line 27 def path File.dirname(pathname) end |
#save ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/imap/backup/configuration.rb', line 31 def save ensure_loaded! FileUtils.mkdir(path) if !File.directory?(path) make_private(path) if !windows? remove_modified_flags remove_deleted_accounts save_data = { version: VERSION, accounts: accounts.map(&:to_h), debug: debug? } File.open(pathname, "w") { |f| f.write(JSON.pretty_generate(save_data)) } FileUtils.chmod(0o600, pathname) if !windows? @data = nil end |