Class: Dutiful::Storage
- Inherits:
-
Object
- Object
- Dutiful::Storage
- Defined in:
- lib/dutiful/storage.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#storage_path ⇒ Object
readonly
Returns the value of attribute storage_path.
Instance Method Summary collapse
- #available? ⇒ Boolean
- #create_dir(file) ⇒ Object
- #exist?(file) ⇒ Boolean
-
#initialize(name: nil, path: nil) ⇒ Storage
constructor
A new instance of Storage.
- #path(path = nil) ⇒ Object
- #sync(file) ⇒ Object
- #synced?(file) ⇒ Boolean
Constructor Details
#initialize(name: nil, path: nil) ⇒ Storage
Returns a new instance of Storage.
7 8 9 10 11 12 13 14 |
# File 'lib/dutiful/storage.rb', line 7 def initialize(name: nil, path: nil) name ||= 'Custom folder' path ||= Tomlrb.load_file("#{Dutiful.dir}/config/#{name.downcase}.toml", symbolize_keys: true)[:storage][:path] @name = name @storage_path = File. path @path = "#{@storage_path}/dutiful" end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/dutiful/storage.rb', line 5 def name @name end |
#storage_path ⇒ Object (readonly)
Returns the value of attribute storage_path.
5 6 7 |
# File 'lib/dutiful/storage.rb', line 5 def storage_path @storage_path end |
Instance Method Details
#available? ⇒ Boolean
16 17 18 |
# File 'lib/dutiful/storage.rb', line 16 def available? File.exist? storage_path end |
#create_dir(file) ⇒ Object
20 21 22 |
# File 'lib/dutiful/storage.rb', line 20 def create_dir(file) FileUtils.mkdir_p File.dirname "#{path}/#{file.path}".shellescape end |
#exist?(file) ⇒ Boolean
24 25 26 |
# File 'lib/dutiful/storage.rb', line 24 def exist?(file) File.exist? "#{path}/#{file.path}" end |
#path(path = nil) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/dutiful/storage.rb', line 28 def path(path = nil) if path "#{@path}/#{path}" else @path end end |
#sync(file) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dutiful/storage.rb', line 36 def sync(file) create_dir file if file.exist? if file.has_backup? && file. > file. Rsync.run file.backup_path.shellescape, file.full_path.shellescape else Rsync.run file.full_path.shellescape, file.backup_path.shellescape end else Rsync.run file.backup_path.shellescape, file.full_path.shellescape end end |
#synced?(file) ⇒ Boolean
50 51 52 |
# File 'lib/dutiful/storage.rb', line 50 def synced?(file) FileUtils.identical? file.full_path, "#{path}/#{file.path}" end |