dutiful 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dutiful/application.rb +1 -1
- data/lib/dutiful/command.rb +2 -8
- data/lib/dutiful/config.rb +20 -0
- data/lib/dutiful/file.rb +1 -1
- data/lib/dutiful/storage.rb +82 -0
- data/lib/dutiful/version.rb +1 -1
- data/lib/dutiful.rb +2 -1
- metadata +4 -4
- data/lib/dutiful/storages/icloud.rb +0 -40
- data/lib/dutiful/storages.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6e4c29b27d8c3ae5615ff691a712b33210694a7
|
4
|
+
data.tar.gz: e8dcdd5062a88e517f0e336af7e6ff99b0413930
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9d9245efc419702a02ae9fdce52efebca255fa0412cd73292c925dbf56bd86a3330bfa7e68d0e8bd7253e20ae5bbc22a2c77512178f338e06bf937416b9e053
|
7
|
+
data.tar.gz: 4515e4eaff2eaaf3654e9026256355c92ff2830b59c5cd941e0c20616ddd44400f2e8d5fe0a45a1ed5ef82417a6275af66bbd65e8a78ab843f119291619b7f43
|
data/lib/dutiful/application.rb
CHANGED
data/lib/dutiful/command.rb
CHANGED
@@ -10,7 +10,7 @@ class Dutiful::Command < Clamp::Command
|
|
10
10
|
option ['-v', '--verbose'], :flag, 'Verbose mode'
|
11
11
|
|
12
12
|
def execute
|
13
|
-
puts "Storage: #{Dutiful::
|
13
|
+
puts "Storage: #{Dutiful::Config.storage.name}\n\n"
|
14
14
|
|
15
15
|
Dutiful::Application.each do |application|
|
16
16
|
puts "#{application.name}:\n"
|
@@ -32,7 +32,7 @@ class Dutiful::Command < Clamp::Command
|
|
32
32
|
|
33
33
|
subcommand 'list', 'List all preference files' do
|
34
34
|
def execute
|
35
|
-
puts "Storage: #{Dutiful::
|
35
|
+
puts "Storage: #{Dutiful::Config.storage.name}\n\n"
|
36
36
|
|
37
37
|
puts Dutiful::Application.all
|
38
38
|
end
|
@@ -49,10 +49,4 @@ class Dutiful::Command < Clamp::Command
|
|
49
49
|
puts 'Not implemented yet'
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
53
|
-
def self.storage
|
54
|
-
@storage ||= if Dutiful::Storage::Icloud.available?
|
55
|
-
Dutiful::Storage::Icloud
|
56
|
-
end
|
57
|
-
end
|
58
52
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Dutiful::Config
|
2
|
+
PATH = ::File.expand_path '~/.dutiful/config.toml'
|
3
|
+
|
4
|
+
def self.storage
|
5
|
+
@storage ||= if content[:storage]
|
6
|
+
name = content[:storage][:name]
|
7
|
+
path = content[:storage][:path]
|
8
|
+
|
9
|
+
Dutiful::Storage.new name: name, path: path
|
10
|
+
else
|
11
|
+
Dutiful::Storage.find { |storage| storage.available? }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.content
|
18
|
+
@content ||= Tomlrb.load_file(PATH, symbolize_keys: true) || {}
|
19
|
+
end
|
20
|
+
end
|
data/lib/dutiful/file.rb
CHANGED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'shellwords'
|
3
|
+
|
4
|
+
class Dutiful::Storage
|
5
|
+
attr_reader :content, :full_path, :path
|
6
|
+
|
7
|
+
def initialize(name: nil, path: nil)
|
8
|
+
name ||= 'Custom folder'
|
9
|
+
path ||= Tomlrb.load_file("config/#{name.downcase}.toml", symbolize_keys: true)[:storage][:path]
|
10
|
+
|
11
|
+
@content = {
|
12
|
+
name: name,
|
13
|
+
path: path
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def available?
|
18
|
+
::File.exist? path
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_dir(file)
|
22
|
+
file_directory_path = ::File.dirname "#{dutiful_path}/#{file.path}"
|
23
|
+
`mkdir -p #{file_directory_path.shellescape}`
|
24
|
+
end
|
25
|
+
|
26
|
+
def dutiful_path
|
27
|
+
"#{path}/dutiful"
|
28
|
+
end
|
29
|
+
|
30
|
+
def exist?(file)
|
31
|
+
::File.exist? "#{dutiful_path}/#{file.path}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def name
|
35
|
+
content[:name]
|
36
|
+
end
|
37
|
+
|
38
|
+
def path
|
39
|
+
@path ||= ::File.expand_path content[:path]
|
40
|
+
end
|
41
|
+
|
42
|
+
def sync(file)
|
43
|
+
create_dir file
|
44
|
+
Rsync.run file.full_path.shellescape, "#{dutiful_path}/#{file.path}".shellescape
|
45
|
+
end
|
46
|
+
|
47
|
+
def synced?(file)
|
48
|
+
FileUtils.identical? file.full_path, "#{dutiful_path}/#{file.path}"
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def self.all
|
54
|
+
Dir.foreach('config').map do |filename|
|
55
|
+
next if filename == '.' or filename == '..'
|
56
|
+
|
57
|
+
data = Tomlrb.load_file("config/#{filename}", symbolize_keys: true)[:storage]
|
58
|
+
Dutiful::Storage.new name: data[:name], path: data[:path]
|
59
|
+
end.compact
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.each
|
63
|
+
return enum_for(:each) unless block_given?
|
64
|
+
|
65
|
+
all.each { |storage| yield storage }
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.find(if_none = nil, &block)
|
69
|
+
result = nil
|
70
|
+
found = false
|
71
|
+
|
72
|
+
each do |element|
|
73
|
+
if block.call(element)
|
74
|
+
result = element
|
75
|
+
found = true
|
76
|
+
break
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
found ? result : if_none && if_none.call
|
81
|
+
end
|
82
|
+
end
|
data/lib/dutiful/version.rb
CHANGED
data/lib/dutiful.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dutiful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno Pinto
|
@@ -77,9 +77,9 @@ files:
|
|
77
77
|
- lib/dutiful.rb
|
78
78
|
- lib/dutiful/application.rb
|
79
79
|
- lib/dutiful/command.rb
|
80
|
+
- lib/dutiful/config.rb
|
80
81
|
- lib/dutiful/file.rb
|
81
|
-
- lib/dutiful/
|
82
|
-
- lib/dutiful/storages/icloud.rb
|
82
|
+
- lib/dutiful/storage.rb
|
83
83
|
- lib/dutiful/version.rb
|
84
84
|
homepage: http://github.com/bpinto/dutiful
|
85
85
|
licenses:
|
@@ -104,5 +104,5 @@ rubyforge_project:
|
|
104
104
|
rubygems_version: 2.4.5
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
|
-
summary: dutiful-0.0.
|
107
|
+
summary: dutiful-0.0.2
|
108
108
|
test_files: []
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'shellwords'
|
3
|
-
|
4
|
-
module Dutiful
|
5
|
-
module Storage
|
6
|
-
class Icloud
|
7
|
-
PATH = ::File.expand_path("~/Library/Mobile Documents")
|
8
|
-
|
9
|
-
def self.available?
|
10
|
-
::File.exist? PATH
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.create_dir(file)
|
14
|
-
directory_path = ::File.dirname "#{dir}/#{file.path}"
|
15
|
-
`mkdir -p #{directory_path.shellescape}`
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.dir
|
19
|
-
"#{PATH}/dutiful"
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.exist?(file)
|
23
|
-
::File.exist? "#{dir}/#{file.path}"
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.name
|
27
|
-
'iCloud'
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.sync(file)
|
31
|
-
create_dir file
|
32
|
-
Rsync.run file.full_path.shellescape, "#{dir}/#{file.path}".shellescape
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.synced?(file)
|
36
|
-
FileUtils.identical? file.full_path, "#{dir}/#{file.path}"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/lib/dutiful/storages.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'dutiful/storages/icloud'
|