flexdot 1.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1cce20c75873ecb10cd057fa7e02177580915e399768e6e2b24a908924717d99
4
- data.tar.gz: 89328d00bc1991493907c2ec558662d4ada76110e6d33052eeaa521ecac64e22
3
+ metadata.gz: abd911eda16fc28b419271e8e75d96f33314f2cc73cc850180966c16cb7fca4f
4
+ data.tar.gz: d3f84e097a314f4fc83772e5cc63874f2c3e0adf9658967b56269b52f3a284d2
5
5
  SHA512:
6
- metadata.gz: 8ba2f0a613eff80271375c8a1eaee73af9e3f573c2ae08ca86b61eff337a4363d55b5d9b45a8212d3b75ad5536215105541f9430910eed87708ec8ca3f583838
7
- data.tar.gz: 3a06a1a126bf0beec0a9b9c7d72f5d96c8778a926d242dc0ed74db0ea198b0a8e6d30c0b64c8a4f40be7525ce731eefec6fe7251a8ac3ad0ad5ab4fef0789013
6
+ metadata.gz: 844806f825d04329fc3fd63a893925e928075afc08c9d6bfcf262bb1b4dac0429edd0525cd68b7744e82dd08deccd10bc41f33e628bb72bb59a94448604b9505
7
+ data.tar.gz: 0dbbd2c56ab172c289206fc8e480be8deef399e2f153213046a83e61497010e8652ce67844f88fade41b29c41a8e8be842e4b8ff3f693d4722e26d6937bd55cd
data/.gitignore CHANGED
@@ -8,5 +8,5 @@
8
8
  /tmp/
9
9
  /Gemfile.lock
10
10
 
11
- /test/home/*
12
- !/test/home/dotfiles/*
11
+ /test/tasks/home/*
12
+ !/test/tasks/home/dotfiles/*
@@ -0,0 +1,29 @@
1
+ ## 2.0.0
2
+
3
+ ### Breaking Changes
4
+
5
+ v1.0.x
6
+
7
+ ```ruby
8
+ # Rakefile
9
+ Flexdot.install_tasks(
10
+ target_dir: '/home/username',
11
+ base_dir: '.'
12
+ )
13
+ ```
14
+
15
+ v2.0.0
16
+
17
+ ```ruby
18
+ Flexdot.setup(
19
+ home_dir: '/home/username',
20
+ dotfiles_dir: '.'
21
+ )
22
+ ```
23
+
24
+ ### Enchancements
25
+
26
+ - Add default_index option fixes #2
27
+ - Option renaming and simplification by default value
28
+
29
+ Please refer to README.md for details.
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ gemspec
4
4
 
5
5
  gem 'rake', '>= 12.0'
6
6
  gem 'minitest', '~> 5.0'
7
+ gem 'rr', '>= 1.2.1'
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Flexdot
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/flexdot.svg)](https://badge.fury.io/rb/flexdot)
3
4
  [![Test](https://github.com/hidakatsuya/flexdot/workflows/Test/badge.svg?branch=master)](https://github.com/hidakatsuya/flexdot/actions?query=workflow%3ATest)
4
5
 
5
6
  A Flexible and Rake based dotfile manager.
@@ -12,25 +13,48 @@ Ruby 2.5+
12
13
 
13
14
  ### Installing
14
15
 
15
- Install it as:
16
-
17
- $ gem install flexdot
18
-
19
- Then, create the following directory structure:
16
+ Create the following directory structure:
20
17
 
21
18
  ```
22
19
  $HOME/
23
- dotfiles/
20
+ ├── dotfiles/
21
+ :
22
+ ```
23
+
24
+ Create a `Gemfile` to install Flexdot:
25
+
26
+ $ cd $HOME/dotfiles
27
+ $ bundle init
28
+
29
+ Add this line to the `Gemfile`:
30
+
31
+ ```ruby
32
+ gem 'flexdot'
24
33
  ```
25
34
 
26
- Create a `$HOME/dotfiles/Rakefile` with the following codes:
35
+ Or install it yourself as:
36
+
37
+ $ gem install flexdot
38
+
39
+ Then, create a `$HOME/dotfiles/Rakefile` with the following codes:
27
40
 
28
41
  ```ruby
29
42
  require 'flexdot'
30
43
 
31
- Flexdot.install_tasks(
32
- base_dir: '.', # $HOME/dotfiles/
33
- target_dir: '/home/username' # $HOME/
44
+ Flexdot.setup(
45
+ home_dir: '/home/username',
46
+
47
+ # (optional)
48
+ # The dotfile directory path.
49
+ # Default '.'.
50
+ dotfiles_dir: '.',
51
+
52
+ # (optional)
53
+ # The `rake install` command will be available to install the dotfile for the specified index file.
54
+ # Default nil.
55
+ #
56
+ # Note that the `rake install` command is always available if you have a single index file.
57
+ default_index: 'name_of_an_index_file'
34
58
  )
35
59
  ```
36
60
 
@@ -94,12 +118,24 @@ $HOME/dotfiles
94
118
  └── Rakefile
95
119
  ```
96
120
 
121
+ ### Rakefile
122
+
123
+ ```ruby
124
+ require 'flexdot'
125
+
126
+ Flexdot.setup(
127
+ home_dir: '..',
128
+ default_index: 'macOS'
129
+ )
130
+ ```
131
+
97
132
  ### Available Commands
98
133
 
99
134
  When you run the `rake -T` command in that directory structure, you should have two installation commands available:
100
135
 
101
136
  $ rake -T
102
137
  rake clear_backups # Clear all backups
138
+ rake install # Install dotfiles for macOS
103
139
  rake install:macOS # Install dotfiles for macOS
104
140
  rake install:ubuntu # Install dotfiles for ubuntu
105
141
 
@@ -177,6 +213,10 @@ ubuntu:
177
213
 
178
214
  ### Installing dotfiles
179
215
 
216
+ $ rake install
217
+
218
+ Or
219
+
180
220
  $ rake install:macOS
181
221
 
182
222
  The following is the output result:
@@ -4,7 +4,7 @@ require_relative 'flexdot/version'
4
4
  require_relative 'flexdot/tasks'
5
5
 
6
6
  module Flexdot
7
- def self.install_tasks(base_dir:, target_dir:)
8
- Tasks.new(base_dir, target_dir).install
7
+ def self.setup(home_dir:, dotfiles_dir: '.', default_index: nil)
8
+ Tasks.new(dotfiles_dir, home_dir, default_index).install
9
9
  end
10
10
  end
@@ -1,27 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flexdot
4
- class Logger
5
- Status = Struct.new(:target_file, :result, :backuped)
4
+ class Console
5
+ Status = Struct.new(:home_file, :result, :backuped)
6
6
 
7
- def initialize(target_dir)
8
- @target_dir = target_dir
7
+ def initialize(dotfiles_dir)
8
+ @dotfiles_dir = dotfiles_dir
9
9
  end
10
10
 
11
- def log(target_file)
12
- status = Status.new(target_file)
11
+ def log(home_file)
12
+ status = Status.new(home_file)
13
13
  yield(status)
14
14
  puts message_for(status)
15
15
  end
16
16
 
17
17
  private
18
18
 
19
- attr_reader :target_dir
19
+ attr_reader :dotfiles_dir
20
20
 
21
21
  def message_for(status)
22
22
  [].tap { |msg|
23
23
  msg << "[#{status.result}]"
24
- msg << status.target_file.relative_path_from(target_dir)
24
+ msg << status.home_file.relative_path_from(dotfiles_dir)
25
25
  msg << '(backup)' if status.backuped
26
26
  }.join(' ')
27
27
  end
@@ -21,7 +21,7 @@ module Flexdot
21
21
  dotfile_path = paths + [k]
22
22
  case v
23
23
  when String
24
- block.call(dotfile_path: File.join(*dotfile_path), target_path: v)
24
+ block.call(dotfile_path: File.join(*dotfile_path), home_file_path: v)
25
25
  when Hash
26
26
  fetch_descendants(v, paths: dotfile_path, &block)
27
27
  else
@@ -2,53 +2,53 @@
2
2
 
3
3
  require 'yaml'
4
4
 
5
- require_relative 'logger'
5
+ require_relative 'console'
6
6
  require_relative 'backup'
7
7
  require_relative 'index'
8
8
 
9
9
  module Flexdot
10
10
  class Installer
11
- def initialize(name, base_dir:, target_dir:)
11
+ def initialize(name, dotfiles_dir:, home_dir:)
12
12
  @name = name
13
- @base_dir = base_dir
14
- @target_dir = target_dir
13
+ @dotfiles_dir = dotfiles_dir
14
+ @home_dir = home_dir
15
15
  @backup = Backup.new
16
- @logger = Logger.new(@target_dir)
16
+ @console = Console.new(@home_dir)
17
17
  end
18
18
 
19
19
  def install(index_file)
20
20
  index = Index.new(YAML.load_file(index_file.to_path))
21
- index.each do |dotfile_path:, target_path:|
22
- install_link(dotfile_path, target_path)
21
+ index.each do |dotfile_path:, home_file_path:|
22
+ install_link(dotfile_path, home_file_path)
23
23
  end
24
24
  end
25
25
 
26
26
  private
27
27
 
28
- attr_reader :name, :base_dir, :target_dir, :backup, :logger
28
+ attr_reader :name, :dotfiles_dir, :home_dir, :backup, :console
29
29
 
30
- def install_link(dotfile_path, target_path)
31
- dotfile = @base_dir.join(dotfile_path).expand_path
32
- target_file = @target_dir.join(target_path, dotfile.basename).expand_path
30
+ def install_link(dotfile_path, home_file_path)
31
+ dotfile = @dotfiles_dir.join(dotfile_path).expand_path
32
+ home_file = @home_dir.join(home_file_path, dotfile.basename).expand_path
33
33
 
34
- logger.log(target_file) do |status|
35
- if target_file.symlink?
36
- if target_file.readlink == dotfile
34
+ console.log(home_file) do |status|
35
+ if home_file.symlink?
36
+ if home_file.readlink == dotfile
37
37
  status.result = :already_linked
38
38
  else
39
- target_file.unlink
40
- target_file.make_symlink(dotfile.to_path)
39
+ home_file.unlink
40
+ home_file.make_symlink(dotfile.to_path)
41
41
  status.result = :link_updated
42
42
  end
43
43
  else
44
- if target_file.exist?
45
- backup.call(target_file)
44
+ if home_file.exist?
45
+ backup.call(home_file)
46
46
  status.backuped = true
47
- elsif !target_file.dirname.exist?
48
- target_file.dirname.mkpath
47
+ elsif !home_file.dirname.exist?
48
+ home_file.dirname.mkpath
49
49
  end
50
50
 
51
- target_file.make_symlink(dotfile.to_path)
51
+ home_file.make_symlink(dotfile.to_path)
52
52
  status.result = :link_created
53
53
  end
54
54
  end
@@ -8,9 +8,12 @@ module Flexdot
8
8
  class Tasks
9
9
  include Rake::DSL
10
10
 
11
- def initialize(base_dir, target_dir)
12
- @base_dir = Pathname.new(base_dir)
13
- @target_dir = Pathname.new(target_dir)
11
+ Index = Struct.new(:filename, :name, keyword_init: true)
12
+
13
+ def initialize(dotfiles_dir, home_dir, default_index_name = nil)
14
+ @default_index_name = default_index_name
15
+ @dotfiles_dir = Pathname.new(dotfiles_dir).expand_path
16
+ @home_dir = Pathname.new(home_dir).expand_path
14
17
  end
15
18
 
16
19
  def install
@@ -20,25 +23,48 @@ module Flexdot
20
23
  end
21
24
 
22
25
  namespace :install do
23
- Pathname.new(base_dir).glob('*.yml') do |index_file|
24
- name = index_file.basename('.*')
25
-
26
- desc "Install dotfiles for #{name}"
27
- task name do
26
+ indexes.each do |index|
27
+ desc "Install dotfiles for #{index.name}"
28
+ task index.name do
28
29
  installer = Installer.new(
29
- name,
30
- base_dir: base_dir,
31
- target_dir: target_dir
30
+ index.name,
31
+ dotfiles_dir: dotfiles_dir,
32
+ home_dir: home_dir
32
33
  )
33
- installer.install(index_file)
34
+ installer.install(index.filename)
34
35
  end
35
36
  end
36
37
  end
38
+
39
+ if default_index
40
+ desc "Install dotfiles for #{default_index.name}"
41
+ task :install do
42
+ Rake::Task["install:#{default_index.name}"].invoke
43
+ end
44
+ end
37
45
  end
38
46
 
39
47
  private
40
48
 
41
- attr_reader :base_dir, :target_dir
49
+ attr_reader :dotfiles_dir, :home_dir
50
+
51
+ def default_index
52
+ @default_index ||=
53
+ if @default_index_name
54
+ ifnone = -> { raise "#{@default_index_name} index is not found" }
55
+ indexes.find(ifnone) { |index| index.name == @default_index_name }
56
+ elsif indexes.size == 1
57
+ indexes.first
58
+ else
59
+ nil
60
+ end
61
+ end
62
+
63
+ def indexes
64
+ @indexes ||= Pathname.new(dotfiles_dir).glob('*.yml').map do |index_file|
65
+ Index.new(name: index_file.basename('.*').to_s, filename: index_file)
66
+ end
67
+ end
42
68
  end
43
69
  end
44
70
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flexdot
4
- VERSION = '1.0.2'
4
+ VERSION = '2.0.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexdot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katsuya Hidaka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-21 00:00:00.000000000 Z
11
+ date: 2020-10-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Flexdot is a Flexible and Rake based dotfile manager
14
14
  email:
@@ -20,6 +20,7 @@ files:
20
20
  - ".github/FUNDING.yml"
21
21
  - ".github/workflows/test.yml"
22
22
  - ".gitignore"
23
+ - CHANGELOG.md
23
24
  - CODE_OF_CONDUCT.md
24
25
  - Gemfile
25
26
  - LICENSE.txt
@@ -28,9 +29,9 @@ files:
28
29
  - flexdot.gemspec
29
30
  - lib/flexdot.rb
30
31
  - lib/flexdot/backup.rb
32
+ - lib/flexdot/console.rb
31
33
  - lib/flexdot/index.rb
32
34
  - lib/flexdot/installer.rb
33
- - lib/flexdot/logger.rb
34
35
  - lib/flexdot/tasks.rb
35
36
  - lib/flexdot/version.rb
36
37
  homepage: https://github.com/hidakatsuya/flexdot