dotsync 0.1.4 → 0.1.6

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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/gem-push.yml +4 -0
  3. data/.rubocop.yml +353 -0
  4. data/CHANGELOG.md +19 -9
  5. data/Gemfile +0 -7
  6. data/Gemfile.lock +20 -1
  7. data/README.md +1 -1
  8. data/Rakefile +4 -2
  9. data/dotsync.gemspec +8 -1
  10. data/exe/console +1 -0
  11. data/exe/dotsync +4 -4
  12. data/lib/dotsync/actions/base_action.rb +2 -0
  13. data/lib/dotsync/actions/concerns/mappings_transfer.rb +18 -1
  14. data/lib/dotsync/actions/pull_action.rb +19 -15
  15. data/lib/dotsync/actions/push_action.rb +10 -8
  16. data/lib/dotsync/actions/watch_action.rb +2 -1
  17. data/lib/dotsync/colors.rb +37 -0
  18. data/lib/dotsync/{actions/config → config}/base_config.rb +2 -1
  19. data/lib/dotsync/{actions/config → config}/pull_action_config.rb +3 -2
  20. data/lib/dotsync/{actions/config → config}/push_action_config.rb +3 -2
  21. data/lib/dotsync/{actions/config → config}/watch_action_config.rb +2 -2
  22. data/lib/dotsync/{actions/config → config}/xdg_base_directory_spec.rb +2 -0
  23. data/lib/dotsync/errors.rb +3 -0
  24. data/lib/dotsync/icons.rb +3 -1
  25. data/lib/dotsync/models/diff.rb +18 -0
  26. data/lib/dotsync/{actions/config/mapping_entry.rb → models/mapping.rb} +25 -13
  27. data/lib/dotsync/runner.rb +37 -32
  28. data/lib/dotsync/tasks/actions.rake +3 -1
  29. data/lib/dotsync/utils/directory_differ.rb +111 -0
  30. data/lib/dotsync/utils/file_transfer.rb +57 -0
  31. data/lib/dotsync/{logger.rb → utils/logger.rb} +2 -0
  32. data/lib/dotsync/{path_utils.rb → utils/path_utils.rb} +4 -2
  33. data/lib/dotsync/version.rb +3 -1
  34. data/lib/dotsync.rb +30 -26
  35. metadata +85 -11
  36. data/lib/dotsync/file_transfer.rb +0 -49
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77103d8c8a478216d16d1dcafe30fb6e6db158df43da7749245b55b8066c2d8c
4
- data.tar.gz: 87762883d28d5afa94020faec9f9fad6d681345872e8dfed92234ded3d0816a4
3
+ metadata.gz: 9b671284dfcdd29739df951c9656b8a0a9867619b57175ac62c5eb6f45137ed0
4
+ data.tar.gz: 26ee6f58257a4a556ea2a7f1eedc06660743fd47e1e073f1977b0a591a2db7f3
5
5
  SHA512:
6
- metadata.gz: fc405ffb5b91817d04bd3cb956afa5072775ae8553ba52560e4c6a4cf769ad8d51c0e3a3a8b7b27b486b7f894cd305a6a2c35d6372c1f7a14fed838353a283cd
7
- data.tar.gz: 809db157e89fd45045a80d75fe55775677efa9b7ebda413f4bfd5e95f765769a3447afbf7edd839f2a68d481e569fe33f59c06e2679ab08b4b097b423023cba3
6
+ metadata.gz: a0206e946ca9040ed97d5385c33fea54b0080e824fbe5c3844adac5bc37cdf452e75efd6ebc40ac1f40d66d1bfa52e9f60ec962ab5a247dda0a8acdea15c2235
7
+ data.tar.gz: 2902acbf3de208132ced6cde1b22f4f3a5a72eacacd6c9c048d3edbf8f20ebf636bf5e7549aec207aba07c642d0a54cf55a6684191a6cb259c66fd31878e32bc
@@ -29,6 +29,10 @@ jobs:
29
29
  run: |
30
30
  bundle exec rake
31
31
 
32
+ - name: Run RuboCop
33
+ run: |
34
+ bundle exec rubocop
35
+
32
36
  - name: Publish to RubyGems
33
37
  if: matrix.ruby == '3.2'
34
38
  run: |
data/.rubocop.yml ADDED
@@ -0,0 +1,353 @@
1
+ plugins:
2
+ - rubocop-rspec
3
+ - rubocop-performance
4
+ - rubocop-md
5
+ - rubocop-rake
6
+
7
+ AllCops:
8
+ # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
9
+ # to ignore them, so only the ones explicitly set in this file are enabled.
10
+ DisabledByDefault: true
11
+
12
+ Performance:
13
+ Exclude:
14
+ - '**/test/**/*'
15
+
16
+ # Prefer &&/|| over and/or.
17
+ Style/AndOr:
18
+ Enabled: true
19
+
20
+ Layout/ClosingHeredocIndentation:
21
+ Enabled: true
22
+
23
+ Layout/ClosingParenthesisIndentation:
24
+ Enabled: true
25
+
26
+ # Align comments with method definitions.
27
+ Layout/CommentIndentation:
28
+ Enabled: true
29
+
30
+ Layout/DefEndAlignment:
31
+ Enabled: true
32
+
33
+ Layout/ElseAlignment:
34
+ Enabled: true
35
+
36
+ # Align `end` with the matching keyword or starting expression except for
37
+ # assignments, where it should be aligned with the LHS.
38
+ Layout/EndAlignment:
39
+ Enabled: true
40
+ EnforcedStyleAlignWith: variable
41
+ AutoCorrect: true
42
+
43
+ Layout/EndOfLine:
44
+ Enabled: true
45
+
46
+ Layout/EmptyLineAfterMagicComment:
47
+ Enabled: true
48
+
49
+ Layout/EmptyLinesAroundAccessModifier:
50
+ Enabled: true
51
+ EnforcedStyle: only_before
52
+
53
+ Layout/EmptyLinesAroundBlockBody:
54
+ Enabled: true
55
+
56
+ # In a regular class definition, no empty lines around the body.
57
+ Layout/EmptyLinesAroundClassBody:
58
+ Enabled: true
59
+
60
+ # In a regular method definition, no empty lines around the body.
61
+ Layout/EmptyLinesAroundMethodBody:
62
+ Enabled: true
63
+
64
+ # In a regular module definition, no empty lines around the body.
65
+ Layout/EmptyLinesAroundModuleBody:
66
+ Enabled: true
67
+
68
+ # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
69
+ Style/HashSyntax:
70
+ Enabled: true
71
+ EnforcedShorthandSyntax: either
72
+
73
+ # Method definitions after `private` or `protected` isolated calls need one
74
+ # extra level of indentation.
75
+ Layout/IndentationConsistency:
76
+ Enabled: true
77
+ EnforcedStyle: indented_internal_methods
78
+ Exclude:
79
+ - '**/*.md'
80
+
81
+ # Two spaces, no tabs (for indentation).
82
+ Layout/IndentationWidth:
83
+ Enabled: true
84
+
85
+ Layout/LeadingCommentSpace:
86
+ Enabled: true
87
+
88
+ Layout/SpaceAfterColon:
89
+ Enabled: true
90
+
91
+ Layout/SpaceAfterComma:
92
+ Enabled: true
93
+
94
+ Layout/SpaceAfterSemicolon:
95
+ Enabled: true
96
+
97
+ Layout/SpaceAroundEqualsInParameterDefault:
98
+ Enabled: true
99
+
100
+ Layout/SpaceAroundKeyword:
101
+ Enabled: true
102
+
103
+ Layout/SpaceAroundOperators:
104
+ Enabled: true
105
+
106
+ Layout/SpaceBeforeComma:
107
+ Enabled: true
108
+
109
+ Layout/SpaceBeforeComment:
110
+ Enabled: true
111
+
112
+ Layout/SpaceBeforeFirstArg:
113
+ Enabled: true
114
+
115
+ Style/DefWithParentheses:
116
+ Enabled: true
117
+
118
+ # Defining a method with parameters needs parentheses.
119
+ Style/MethodDefParentheses:
120
+ Enabled: true
121
+
122
+ Style/ExplicitBlockArgument:
123
+ Enabled: true
124
+
125
+ Style/FrozenStringLiteralComment:
126
+ Enabled: true
127
+ EnforcedStyle: always
128
+ Exclude:
129
+ - 'actionview/test/**/*.builder'
130
+ - 'actionview/test/**/*.ruby'
131
+ - 'actionpack/test/**/*.builder'
132
+ - 'actionpack/test/**/*.ruby'
133
+ - 'activestorage/db/migrate/**/*.rb'
134
+ - 'activestorage/db/update_migrate/**/*.rb'
135
+ - 'actionmailbox/db/migrate/**/*.rb'
136
+ - 'actiontext/db/migrate/**/*.rb'
137
+ - '**/*.md'
138
+
139
+ Style/MapToHash:
140
+ Enabled: true
141
+
142
+ Style/RedundantFreeze:
143
+ Enabled: true
144
+
145
+ # Use `foo {}` not `foo{}`.
146
+ Layout/SpaceBeforeBlockBraces:
147
+ Enabled: true
148
+
149
+ # Use `foo { bar }` not `foo {bar}`.
150
+ Layout/SpaceInsideBlockBraces:
151
+ Enabled: true
152
+ EnforcedStyleForEmptyBraces: space
153
+
154
+ # Use `{ a: 1 }` not `{a:1}`.
155
+ Layout/SpaceInsideHashLiteralBraces:
156
+ Enabled: true
157
+
158
+ Layout/SpaceInsideParens:
159
+ Enabled: true
160
+
161
+ # Check quotes usage according to lint rule below.
162
+ Style/StringLiterals:
163
+ Enabled: true
164
+ EnforcedStyle: double_quotes
165
+
166
+ # Detect hard tabs, no hard tabs.
167
+ Layout/IndentationStyle:
168
+ Enabled: true
169
+
170
+ # Empty lines should not have any spaces.
171
+ Layout/TrailingEmptyLines:
172
+ Enabled: true
173
+
174
+ # No trailing whitespace.
175
+ Layout/TrailingWhitespace:
176
+ Enabled: true
177
+
178
+ # Use quotes for string literals when they are enough.
179
+ Style/RedundantPercentQ:
180
+ Enabled: true
181
+
182
+ Lint/NestedMethodDefinition:
183
+ Enabled: true
184
+
185
+ Lint/AmbiguousOperator:
186
+ Enabled: true
187
+
188
+ Lint/AmbiguousRegexpLiteral:
189
+ Enabled: true
190
+
191
+ Lint/Debugger:
192
+ Enabled: true
193
+ DebuggerRequires:
194
+ - debug
195
+
196
+ Lint/DuplicateRequire:
197
+ Enabled: true
198
+
199
+ Lint/DuplicateMagicComment:
200
+ Enabled: true
201
+
202
+ Lint/DuplicateMethods:
203
+ Enabled: true
204
+
205
+ Lint/ErbNewArguments:
206
+ Enabled: true
207
+
208
+ Lint/EnsureReturn:
209
+ Enabled: true
210
+
211
+ Lint/MissingCopEnableDirective:
212
+ Enabled: true
213
+
214
+ # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
215
+ Lint/RequireParentheses:
216
+ Enabled: true
217
+
218
+ Lint/RedundantCopDisableDirective:
219
+ Enabled: true
220
+
221
+ Lint/RedundantCopEnableDirective:
222
+ Enabled: true
223
+
224
+ Lint/RedundantRequireStatement:
225
+ Enabled: true
226
+
227
+ Lint/RedundantStringCoercion:
228
+ Enabled: true
229
+
230
+ Lint/RedundantSafeNavigation:
231
+ Enabled: true
232
+
233
+ Lint/UriEscapeUnescape:
234
+ Enabled: true
235
+
236
+ Lint/UselessAssignment:
237
+ Enabled: true
238
+
239
+ Lint/DeprecatedClassMethods:
240
+ Enabled: true
241
+
242
+ Lint/InterpolationCheck:
243
+ Enabled: true
244
+ Exclude:
245
+ - '**/test/**/*'
246
+
247
+ Lint/SafeNavigationChain:
248
+ Enabled: true
249
+
250
+ Style/EvalWithLocation:
251
+ Enabled: true
252
+ Exclude:
253
+ - '**/test/**/*'
254
+
255
+ Style/ParenthesesAroundCondition:
256
+ Enabled: true
257
+
258
+ Style/HashTransformKeys:
259
+ Enabled: true
260
+
261
+ Style/HashTransformValues:
262
+ Enabled: true
263
+
264
+ Style/RedundantBegin:
265
+ Enabled: true
266
+
267
+ Style/RedundantReturn:
268
+ Enabled: true
269
+ AllowMultipleReturnValues: true
270
+
271
+ Style/RedundantRegexpEscape:
272
+ Enabled: true
273
+
274
+ Style/Semicolon:
275
+ Enabled: true
276
+ AllowAsExpressionSeparator: true
277
+
278
+ # Prefer Foo.method over Foo::method
279
+ Style/ColonMethodCall:
280
+ Enabled: true
281
+
282
+ Style/TrivialAccessors:
283
+ Enabled: true
284
+
285
+ # Prefer a = b || c over a = b ? b : c
286
+ Style/RedundantCondition:
287
+ Enabled: true
288
+
289
+ Style/RedundantDoubleSplatHashBraces:
290
+ Enabled: true
291
+
292
+ Style/OpenStructUse:
293
+ Enabled: true
294
+
295
+ Style/ArrayIntersect:
296
+ Enabled: true
297
+
298
+ Style/KeywordArgumentsMerging:
299
+ Enabled: true
300
+
301
+ Performance/BindCall:
302
+ Enabled: true
303
+
304
+ Performance/FlatMap:
305
+ Enabled: true
306
+
307
+ Performance/MapCompact:
308
+ Enabled: true
309
+
310
+ Performance/SelectMap:
311
+ Enabled: true
312
+
313
+ Performance/RedundantMerge:
314
+ Enabled: true
315
+
316
+ Performance/StartWith:
317
+ Enabled: true
318
+
319
+ Performance/EndWith:
320
+ Enabled: true
321
+
322
+ Performance/RegexpMatch:
323
+ Enabled: true
324
+
325
+ Performance/ReverseEach:
326
+ Enabled: true
327
+
328
+ Performance/StringReplacement:
329
+ Enabled: true
330
+
331
+ Performance/DeletePrefix:
332
+ Enabled: true
333
+
334
+ Performance/DeleteSuffix:
335
+ Enabled: true
336
+
337
+ Performance/InefficientHashSearch:
338
+ Enabled: true
339
+
340
+ Performance/ConstantRegexp:
341
+ Enabled: true
342
+
343
+ Performance/RedundantStringChars:
344
+ Enabled: true
345
+
346
+ Performance/StringInclude:
347
+ Enabled: true
348
+
349
+ Markdown:
350
+ # Whether to run RuboCop against non-valid snippets
351
+ WarnInvalid: true
352
+ # Whether to lint codeblocks without code attributes
353
+ Autodetect: false
data/CHANGELOG.md CHANGED
@@ -1,17 +1,27 @@
1
+ # 0.1.6
2
+
3
+ - Show diff changes on PushAction and PullAction.
4
+ - Fixed load custom config (Icons, Colors)
5
+
6
+ # 0.1.5
7
+
8
+ - Fixes backup when destination folder does not exist
9
+ - Add rubocop to Github Actions
10
+
1
11
  # 0.1.4
2
12
 
3
- Colorized environment variables
4
- Fixed colorized mapping entries
13
+ - Colorized environment variables
14
+ - Fixed colorized mapping entries
5
15
 
6
16
  # 0.1.3
7
17
 
8
- PushAction: Avoid error on missing destination
9
- Unify mappings print. Use icon for ignores presence.
10
- Extracted icons to its own module
11
- Reviewed icons
12
- Updated README with existing mapping entries icons
13
- Customizable icons
14
- Logger review
18
+ - PushAction: Avoid error on missing destination
19
+ - Unify mappings print. Use icon for ignores presence.
20
+ - Extracted icons to its own module
21
+ - Reviewed icons
22
+ - Updated README with existing mapping entries icons
23
+ - Customizable icons
24
+ - Logger review
15
25
 
16
26
  # 0.1.2
17
27
 
data/Gemfile CHANGED
@@ -4,10 +4,3 @@ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in dotsync.gemspec
6
6
  gemspec
7
-
8
- # gem "irb"
9
- # gem "rake", "~> 13.0"
10
- #
11
- # gem "rspec", "~> 3.0"
12
- #
13
- # gem "rubocop", "~> 1.21"
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dotsync (0.1.4)
4
+ dotsync (0.1.6)
5
5
  fileutils (~> 1.7.3)
6
+ find (~> 0.2.0)
6
7
  listen (~> 3.9.0)
7
8
  logger (~> 1.7.0)
8
9
  ostruct (~> 0.6.3)
@@ -26,6 +27,7 @@ GEM
26
27
  ffi (1.17.2-x86_64-linux-gnu)
27
28
  ffi (1.17.2-x86_64-linux-musl)
28
29
  fileutils (1.7.3)
30
+ find (0.2.0)
29
31
  json (2.15.2)
30
32
  language_server-protocol (3.17.0.5)
31
33
  lint_roller (1.1.0)
@@ -75,6 +77,19 @@ GEM
75
77
  rubocop-ast (1.47.1)
76
78
  parser (>= 3.3.7.2)
77
79
  prism (~> 1.4)
80
+ rubocop-md (2.0.3)
81
+ lint_roller (~> 1.1)
82
+ rubocop (>= 1.72.1)
83
+ rubocop-performance (1.26.1)
84
+ lint_roller (~> 1.1)
85
+ rubocop (>= 1.75.0, < 2.0)
86
+ rubocop-ast (>= 1.47.1, < 2.0)
87
+ rubocop-rake (0.7.1)
88
+ lint_roller (~> 1.1)
89
+ rubocop (>= 1.72.1)
90
+ rubocop-rspec (3.7.0)
91
+ lint_roller (~> 1.1)
92
+ rubocop (~> 1.72, >= 1.72.1)
78
93
  ruby-lsp (0.26.1)
79
94
  language_server-protocol (~> 3.17.0)
80
95
  prism (>= 1.2, < 2.0)
@@ -106,6 +121,10 @@ DEPENDENCIES
106
121
  rake (~> 13.3.0)
107
122
  rspec (~> 3.13.1)
108
123
  rubocop (~> 1.81.1)
124
+ rubocop-md (~> 2.0.3)
125
+ rubocop-performance (~> 1.26.1)
126
+ rubocop-rake (~> 0.7.1)
127
+ rubocop-rspec (~> 3.7.0)
109
128
  ruby-lsp (~> 0.26.1)
110
129
  timecop (~> 0.9.10)
111
130
 
data/README.md CHANGED
@@ -11,7 +11,7 @@ Welcome to Dotsync! This gem helps you manage and synchronize your dotfiles effo
11
11
  Add this line to your application's Gemfile:
12
12
 
13
13
  ```ruby
14
- gem 'dotsync'
14
+ gem "dotsync"
15
15
  ```
16
16
 
17
17
  And then execute:
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
4
- require 'dotsync'
6
+ require "dotsync"
5
7
 
6
8
  # Load all tasks
7
- Dir.glob(File.join(Gem.loaded_specs['dotsync'].full_gem_path, 'lib', 'dotsync', 'tasks', '**/*.rake')).each { |f| load f }
9
+ Dir.glob(File.join(Gem.loaded_specs["dotsync"].full_gem_path, "lib", "dotsync", "tasks", "**/*.rake")).each { |f| load f }
8
10
 
9
11
  RSpec::Core::RakeTask.new(:spec) do |t|
10
12
  # ENV['TEST_ENV'] = 'true'
data/dotsync.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "lib/dotsync/version"
2
4
 
3
5
  Gem::Specification.new do |spec|
@@ -18,7 +20,7 @@ Gem::Specification.new do |spec|
18
20
 
19
21
  # Specify which files should be added to the gem when it is released.
20
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
22
24
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
25
  end
24
26
  spec.bindir = "exe"
@@ -30,9 +32,14 @@ Gem::Specification.new do |spec|
30
32
  spec.add_dependency "fileutils", "~> 1.7.3"
31
33
  spec.add_dependency "logger", "~> 1.7.0" # No longer part of default gems from Ruby 3.5
32
34
  spec.add_dependency "ostruct", "~> 0.6.3" # No longer part of default gems from Ruby 3.5
35
+ spec.add_dependency "find", "~> 0.2.0"
33
36
  spec.add_development_dependency "rake", "~> 13.3.0"
34
37
  spec.add_development_dependency "rspec", "~> 3.13.1"
35
38
  spec.add_development_dependency "rubocop", "~> 1.81.1"
39
+ spec.add_development_dependency "rubocop-rspec", "~> 3.7.0"
40
+ spec.add_development_dependency "rubocop-performance", "~> 1.26.1"
41
+ spec.add_development_dependency "rubocop-rake", "~> 0.7.1"
42
+ spec.add_development_dependency "rubocop-md", "~> 2.0.3"
36
43
  spec.add_development_dependency "timecop", "~> 0.9.10"
37
44
  spec.add_development_dependency "ruby-lsp", "~> 0.26.1"
38
45
  end
data/exe/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require "dotsync"
data/exe/dotsync CHANGED
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require_relative '../lib/dotsync'
4
- require 'optparse'
4
+ require_relative "../lib/dotsync"
5
+ require "optparse"
5
6
 
6
- options = {}
7
+ {}
7
8
 
8
9
  opt_parser = OptionParser.new do |opts|
9
10
  opts.banner = <<~BANNER
@@ -44,4 +45,3 @@ else
44
45
  end
45
46
  exit 1
46
47
  end
47
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dotsync
2
4
  class BaseAction
3
5
  include Dotsync::PathUtils
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dotsync
2
4
  module MappingsTransfer
3
5
  extend Forwardable # def_delegator
@@ -5,13 +7,28 @@ module Dotsync
5
7
  def_delegator :@config, :mappings
6
8
 
7
9
  def show_mappings
8
- info("Mappings:", icon: :config, )
10
+ info("Mappings:", icon: :config,)
9
11
 
10
12
  mappings.each do |mapping|
11
13
  logger.log(" #{mapping}")
12
14
  end
13
15
  end
14
16
 
17
+ def show_changes
18
+ diffs = valid_mappings.map do |mapping|
19
+ Dotsync::DirectoryDiffer.new(mapping).diff
20
+ end
21
+ diffs.flat_map(&:additions).sort.each do |path|
22
+ logger.log(" #{path}", color: Dotsync::Colors.diff_additions)
23
+ end
24
+ diffs.flat_map(&:modifications).sort.each do |path|
25
+ logger.log(" #{path}", color: Dotsync::Colors.diff_modifications)
26
+ end
27
+ diffs.flat_map(&:removals).sort.each do |path|
28
+ logger.log(" #{path}", color: Dotsync::Colors.diff_removals)
29
+ end
30
+ end
31
+
15
32
  def transfer_mappings
16
33
  valid_mappings.each do |mapping|
17
34
  Dotsync::FileTransfer.new(mapping).transfer
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dotsync
2
4
  class PullAction < BaseAction
3
5
  include MappingsTransfer
@@ -6,6 +8,7 @@ module Dotsync
6
8
 
7
9
  def execute
8
10
  show_config
11
+ show_changes
9
12
  if create_backup
10
13
  show_backup
11
14
  purge_old_backups
@@ -14,7 +17,6 @@ module Dotsync
14
17
  end
15
18
 
16
19
  private
17
-
18
20
  def show_config
19
21
  show_mappings
20
22
  end
@@ -22,44 +24,46 @@ module Dotsync
22
24
  def pull_dotfiles
23
25
  transfer_mappings
24
26
 
25
- action("Dotfiles pulled", icon: :copy)
27
+ action("Dotfiles pulled")
26
28
  end
27
29
 
28
30
  def show_backup
29
- action("Backup created:", icon: :backup)
30
- logger.log(" #{backup_path}")
31
+ action("Backup created:")
32
+ logger.log(" #{backup_root_path}")
31
33
  end
32
34
 
33
35
  def timestamp
34
- Time.now.strftime('%Y%m%d%H%M%S')
36
+ Time.now.strftime("%Y%m%d%H%M%S")
35
37
  end
36
38
 
37
- def backup_path
38
- @backup_path ||= File.join(backups_root, timestamp)
39
+ def backup_root_path
40
+ @backup_root_path ||= File.join(backups_root, timestamp)
39
41
  end
40
42
 
41
43
  def create_backup
42
44
  return false unless valid_mappings.any?
43
- FileUtils.mkdir_p(backup_path)
44
- mappings.each do |mapping|
45
- next unless File.exist?(mapping.dest)
45
+ FileUtils.mkdir_p(backup_root_path)
46
+ valid_mappings.each do |mapping|
47
+ next unless mapping.backup_possible?
48
+ backup_path = File.join(backup_root_path, mapping.backup_basename)
46
49
  if File.file?(mapping.src)
47
- FileUtils.cp(mapping.dest, File.join(backup_path, File.basename(mapping.dest)))
50
+ FileUtils.cp(mapping.dest, backup_path)
48
51
  else
49
- FileUtils.cp_r(mapping.dest, File.join(backup_path, File.basename(mapping.dest)))
52
+ FileUtils.cp_r(mapping.dest, backup_path)
50
53
  end
51
54
  end
52
55
  true
53
56
  end
54
57
 
55
58
  def purge_old_backups
56
- backups = Dir[File.join(backups_root, '*')].sort.reverse
59
+ backups = Dir[File.join(backups_root, "*")].sort.reverse
57
60
  if backups.size > 10
58
- info("Maximum of 10 backups retained")
61
+ logger.log("Maximum of 10 backups retained")
59
62
 
63
+ action("Backup deleted:")
60
64
  backups[10..].each do |path|
61
65
  FileUtils.rm_rf(path)
62
- info("Old backup deleted: #{path}", icon: :delete)
66
+ logger.log(" #{path}")
63
67
  end
64
68
  end
65
69
  end