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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 102221a85fbf0c21b37679ddbdf1cb40bedfdec9
4
- data.tar.gz: d222a3af107ab1cc13b597179878ca55e146dc8c
3
+ metadata.gz: e6e4c29b27d8c3ae5615ff691a712b33210694a7
4
+ data.tar.gz: e8dcdd5062a88e517f0e336af7e6ff99b0413930
5
5
  SHA512:
6
- metadata.gz: 90a5ac97f5783d609c18c5db40b91dcf6496fd95dc4d46d8ff02e2ae8b7fcb182766bb7d280cd4172de7c1c1755c0d78d109890e8ecb45b75728d3ddd5b65c6c
7
- data.tar.gz: 3ea6eef9dd4b2f100d8c9d216019018a9fbb0e95894648700f258ae0e37210c1d8918e4f43adc1bd7f66e7d0eee3b089adf85d4f7668236c6ec13c2c5a339513
6
+ metadata.gz: e9d9245efc419702a02ae9fdce52efebca255fa0412cd73292c925dbf56bd86a3330bfa7e68d0e8bd7253e20ae5bbc22a2c77512178f338e06bf937416b9e053
7
+ data.tar.gz: 4515e4eaff2eaaf3654e9026256355c92ff2830b59c5cd941e0c20616ddd44400f2e8d5fe0a45a1ed5ef82417a6275af66bbd65e8a78ab843f119291619b7f43
@@ -19,7 +19,7 @@ module Dutiful
19
19
  def sync
20
20
  files.each do |file|
21
21
  if file.exist?
22
- result = Dutiful::Command.storage.sync(file) if file.exist?
22
+ result = Dutiful::Config.storage.sync(file) if file.exist?
23
23
  yield file, result
24
24
  else
25
25
  yield file
@@ -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::Command.storage.name}\n\n"
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::Command.storage.name}\n\n"
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
@@ -12,7 +12,7 @@ module Dutiful
12
12
  end
13
13
 
14
14
  def synced?
15
- Dutiful::Command.storage.exist?(self) && Dutiful::Command.storage.synced?(self)
15
+ Dutiful::Config.storage.exist?(self) && Dutiful::Config.storage.synced?(self)
16
16
  end
17
17
  end
18
18
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Dutiful
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/dutiful.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'dutiful/application'
2
2
  require 'dutiful/command'
3
+ require 'dutiful/config'
3
4
  require 'dutiful/file'
4
- require 'dutiful/storages'
5
+ require 'dutiful/storage'
5
6
  require 'colorize'
6
7
  require 'rsync'
7
8
  require 'tomlrb'
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.1
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/storages.rb
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.1
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
@@ -1 +0,0 @@
1
- require 'dutiful/storages/icloud'