dotify 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/mattdbridges/dotify.png)](http://travis-ci.org/mattdbridges/dotify) [![Dependency Status](https://gemnasium.com/mattdbridges/dotify.png)](https://gemnasium.com/mattdbridges/dotify)
4
4
 
5
- Dotify is a simple CLI tool to make managing dotfiles on your system easy. When developing on a Linux/Unix basic system, keeping track of all of those dotfiles in the home directory can be pain. Some developers do not even bother managing them and many have come up with their own static or even dynamic way of managing them. This is a need in the community, and this tool makes managing these crazy files a breeze.
5
+ Dotify is a simple CLI tool to make managing dotfiles on your system easy. When developing on a Linux/Unix-based system, keeping track of all of those dotfiles in the home directory can be pain. Some developers do not even bother managing them and many have come up with their own static or even dynamic way of managing them. This is a need in the community, and this tool makes managing these crazy files a breeze.
6
6
 
7
7
  ## Ruby Version Support
8
8
 
9
- As this is a gem for use on your local system, I understand there are still many Ruby developers still stuck with using Ruby 1.8. As such, Dotify supports the following Ruby versions definitively:
9
+ As this is a gem for use on your local system, I know there are still many Ruby developers still stuck with using Ruby 1.8. As such, Dotify supports the following Ruby versions definitively:
10
10
 
11
11
  * 1.8.7
12
12
  * 1.9.2
@@ -16,15 +16,11 @@ As this is a gem for use on your local system, I understand there are still many
16
16
 
17
17
  ## Installation
18
18
 
19
- It is highly recommended that you just install this gem manually since it is only managing files on your local system:Add this line to your application's Gemfile:
19
+ Run this command in the command line to install Dotify:
20
20
 
21
21
  $ gem install dotify
22
22
 
23
- ## Usage
24
-
25
- As dotify is a CLI tool, everything is done in the command line. Here are the current available methods for managing dotfiles.
26
-
27
- ### Setting up and installing Dotify
23
+ ## Installation
28
24
 
29
25
  To install Dotify, you must first run `dotify install` in your terminal.
30
26
 
@@ -48,14 +44,14 @@ During the installation process, a Vim instance will open with a sample `.dotrc`
48
44
 
49
45
  Alternatively, you could run `dotify setup` to setup Dotify's configuration, followed by `dotify install` to add the initial files into Dotify.
50
46
 
51
- ### Link single files
47
+ ## Link single files
52
48
 
53
49
  After you have setup Dotify, you can add files one by one if you did not add them during setup.
54
50
 
55
51
  $ dotify link .vimrc
56
52
  linked /Users/computer-user/.vimrc
57
53
 
58
- ### Unlink the chains...
54
+ ## Unlink the chains...
59
55
 
60
56
  Don't want any of the dotfiles anymore? Or want to drop one? Well, I'm not one to question. Go ahead and move them back into the home directory.
61
57
 
@@ -91,7 +87,7 @@ The whole purpose of this gem was to manage the dotfiles on your system. What be
91
87
 
92
88
  The `.dotrc` file in your home directory serves as the configuration file for Dotify. It is a [YAML](http://www.yaml.org/) formatted file.
93
89
 
94
- #### Dotify Editor
90
+ ### Dotify Editor
95
91
 
96
92
  When you run `dotify edit [DOTFILE]`, by default the file opens in Vim for editing. You can change this by adding this following to your `.dotrc` file.
97
93
 
@@ -100,7 +96,7 @@ When you run `dotify edit [DOTFILE]`, by default the file opens in Vim for editi
100
96
 
101
97
  Vim and Emacs are the only two editors that have been successfully used with this configuration option, but if you find another, please [let me know](https://github.com/mattdbridges/dotify/issues/new) and I will update the documentation.
102
98
 
103
- #### Ignoring files
99
+ ### Ignoring files
104
100
 
105
101
  When you are linking files in your Dotify directory, some files you do not want ever want to link (`.git`, `.gitmodules`, `.gitignore`, .etc) because they are used specifically for that directory (such as git versioning). You can configure Dotify to ignore these files when calling `dotify link` in the `.dotrc` in this way:
106
102
 
@@ -5,11 +5,11 @@ require 'fileutils'
5
5
 
6
6
  module Dotify
7
7
 
8
- autoload :Config, 'dotify/config'
9
- autoload :Files, 'dotify/files'
10
- autoload :List, 'dotify/list'
11
- autoload :Unit, 'dotify/unit'
12
- autoload :CLI, 'dotify/cli'
8
+ autoload :Config, 'dotify/config'
9
+ autoload :Collection, 'dotify/collection'
10
+ autoload :List, 'dotify/list'
11
+ autoload :Unit, 'dotify/unit'
12
+ autoload :CLI, 'dotify/cli'
13
13
 
14
14
  def self.installed?
15
15
  Config.installed?
@@ -36,7 +36,7 @@ module Dotify
36
36
  method_option :verbose, :aliases => '-v', :type => :boolean, :default => true, :desc => "Display file creation and status updates."
37
37
  method_option :push, :aliases => '-p', :type => :boolean, :default => false, :desc => "Force the push to the remote repository."
38
38
  def save
39
- if File.exists? Files.dotify('.git') # if the Dotify directory has been made a git repo
39
+ if File.exists? Config.path('.git') # if the Dotify directory has been made a git repo
40
40
  repo = ::Git.open(Config.path)
41
41
  changed = repo.status.changed
42
42
  if changed.size > 0
@@ -148,9 +148,9 @@ module Dotify
148
148
  # Link a single file
149
149
  return link_file Unit.new(file), options unless file.nil?
150
150
  # Relink the files
151
- return Files.linked { |file| link_file(file, options) } if options[:relink]
151
+ return collection.linked.each { |file| link_file(file, options) } if options[:relink]
152
152
  # Link the files
153
- Files.unlinked { |file| link_file(file, options) }
153
+ collection.unlinked.each { |file| link_file(file, options) }
154
154
  end
155
155
 
156
156
  desc 'unlink [[FILENAME]]', "Unlink one or all of your dotfiles (FILENAME is optional)"
@@ -166,11 +166,15 @@ module Dotify
166
166
  # Unlink a single file
167
167
  return unlink_file Unit.new(file), options unless file.nil?
168
168
  # Unlink the files
169
- Files.linked { |file| unlink_file(file, options) }
169
+ collection.linked.each { |file| unlink_file(file, options) }
170
170
  end
171
171
 
172
172
  no_tasks do
173
173
 
174
+ def collection
175
+ @collection ||= Collection.new
176
+ end
177
+
174
178
  def not_setup_warning
175
179
  say "Dotify has not been setup yet! You need to run 'dotify setup' first.", :yellow
176
180
  end
@@ -179,7 +183,7 @@ module Dotify
179
183
  say "'#{file}' does not exist in Dotify.", :blue unless file.linked?
180
184
  if options[:force] == true || yes?("Do you want to unlink #{file} from the home directory? [Yn]", :blue)
181
185
  file.unlink
182
- say_status :unlinked, file.dotfile
186
+ say_status :unlinked, file.home
183
187
  end
184
188
  end
185
189
 
@@ -188,7 +192,7 @@ module Dotify
188
192
  return say "'#{file}' does not exist in the home directory.", :blue unless file.in_home_dir?
189
193
  if options[:force] == true || yes?("Do you want to link #{file} to the home directory? [Yn]", :blue)
190
194
  file.link
191
- say_status :linked, file.dotfile
195
+ say_status :linked, file.home
192
196
  end
193
197
  end
194
198
 
@@ -0,0 +1,43 @@
1
+ Dotify::Config.load_config!
2
+
3
+ module Dotify
4
+ class Collection
5
+
6
+ include Enumerable
7
+
8
+ attr_accessor :units
9
+
10
+ # Pulls an array of Units from the home
11
+ # directory.
12
+ def initialize
13
+ @units ||= List.home
14
+ end
15
+
16
+ # Defined each method for Enumerable
17
+ def each(&block)
18
+ @units.each(&block)
19
+ end
20
+
21
+ # Linked files are those files which have a
22
+ # symbolic link pointing to the Dotify file.
23
+ def linked
24
+ select(&:linked?)
25
+ end
26
+
27
+ # Unlinked files are, of course, the opposite
28
+ # of linked files. These are Dotify files which
29
+ # Have no home dir files that are linked to them.
30
+ def unlinked
31
+ reject(&:linked?)
32
+ end
33
+
34
+ def to_s
35
+ @units
36
+ end
37
+
38
+ def inspect
39
+ @units.map(&:inspect)
40
+ end
41
+
42
+ end
43
+ end
@@ -19,12 +19,14 @@ module Dotify
19
19
  @dirname ||= DIRNAME
20
20
  end
21
21
 
22
- def home
23
- Thor::Util.user_home
22
+ def home(file_or_path = nil)
23
+ file_or_path.nil? ? user_home : File.join(user_home, file_or_path)
24
24
  end
25
25
 
26
- def path
27
- File.join(home, dirname)
26
+ def path(file_or_path = nil)
27
+ joins = [self.home, dirname]
28
+ joins << file_or_path unless file_or_path.nil?
29
+ File.join *joins
28
30
  end
29
31
 
30
32
  def installed?
@@ -54,6 +56,10 @@ module Dotify
54
56
 
55
57
  private
56
58
 
59
+ def user_home
60
+ Thor::Util.user_home
61
+ end
62
+
57
63
  def symbolize_keys!(opts)
58
64
  sym_opts = {}
59
65
  opts.each do |key, value|
@@ -5,12 +5,12 @@ module Dotify
5
5
  class << self
6
6
 
7
7
  def home
8
- result = units(Files.dotfile('.*'))
8
+ result = units(Config.home('.*'))
9
9
  filter_ignore_files!(result, :dotfiles)
10
10
  end
11
11
 
12
12
  def dotify
13
- result = units(Files.dotify('.*'))
13
+ result = units(Config.path('.*'))
14
14
  filter_ignore_files!(result, :dotify)
15
15
  end
16
16
 
@@ -32,11 +32,7 @@ module Dotify
32
32
 
33
33
  include Actions
34
34
 
35
- # Attributes on the file itself
36
- attr_accessor :filename, :dotify, :dotfile
37
-
38
- # Attributes about the file's status in the filesystem
39
- attr_accessor :linked, :added
35
+ attr_accessor :filename, :dotify, :dotfile, :linked
40
36
 
41
37
  def initialize(file)
42
38
  @filename = File.basename(file)
@@ -44,16 +40,13 @@ module Dotify
44
40
  end
45
41
 
46
42
  def dotify
47
- @dotify ||= Files.dotify(@filename)
43
+ @dotify ||= Config.path(@filename)
48
44
  end
49
45
 
50
46
  def dotfile
51
- @dotfile ||= Files.dotfile(@filename)
52
- end
53
-
54
- def added?
55
- in_dotify? && !linked_to_dotify?
47
+ @dotfile ||= Config.home(@filename)
56
48
  end
49
+ alias :home :dotfile
57
50
 
58
51
  def linked?
59
52
  in_dotify? && linked_to_dotify?
@@ -72,7 +65,7 @@ module Dotify
72
65
  end
73
66
 
74
67
  def inspect
75
- "#<Dotify::Unit @filename='#{@filename}' @added=#{added?} @linked=#{linked?}>"
68
+ "#<Dotify::Unit @filename='#{@filename}' @linked=#{linked?}>"
76
69
  end
77
70
 
78
71
  def linked_to_dotify?
@@ -1,3 +1,3 @@
1
1
  module Dotify
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'dotify'
2
3
  require 'thor'
3
4
 
4
5
  module Dotify
@@ -7,6 +8,7 @@ module Dotify
7
8
  before do
8
9
  Dotify.stub(:installed?).and_return true
9
10
  cli.stub(:exec)
11
+ cli.stub(:collection) { Collection.new }
10
12
  end
11
13
 
12
14
  describe CLI, "#edit" do
@@ -29,13 +31,23 @@ module Dotify
29
31
  end
30
32
 
31
33
  describe CLI, "#link" do
34
+ before do
35
+ cli.stub(:collection).and_return(
36
+ double('collection', {
37
+ :unlinked => [double('.zshrc', :in_home_dir? => true, :linked? => false), double('.gitconfig', :in_home_dir? => true, :linked? => false)],
38
+ :linked => [double('.vimrc', :in_home_dir? => true, :linked? => true)]
39
+ })
40
+ )
41
+ cli.stub(:link_file)
42
+ end
32
43
  it "should loop through all unlinked files" do
33
- Files.should_receive(:unlinked)
44
+ cli.collection.should_receive(:unlinked)
45
+ cli.should_receive(:link_file).exactly(cli.collection.unlinked.size).times
34
46
  cli.link
35
47
  end
36
48
  it "should relink all of the files located in Dotify" do
37
- Files.should_not_receive(:unlinked)
38
- Files.should_receive(:linked)
49
+ cli.collection.should_not_receive(:unlinked)
50
+ cli.collection.should_receive(:linked)
39
51
  cli.stub(:options).and_return({ :relink => true })
40
52
  cli.link
41
53
  end
@@ -51,8 +63,18 @@ module Dotify
51
63
  end
52
64
 
53
65
  describe CLI, "#unlink" do
66
+ before do
67
+ cli.stub(:collection).and_return double(:linked => [double('.vimrc', :linked? => true), double('.bashrc', :linked? => true)])
68
+ cli.stub(:unlink_file)
69
+ end
54
70
  it "should loop through all unlinked files" do
55
- Files.should_receive(:linked)
71
+ cli.collection.should_receive(:linked)
72
+ cli.unlink
73
+ end
74
+ it "should call CLI#unlink_file the right number of times" do
75
+ cli.collection.should_receive(:linked)
76
+ cli.stub(:unlink_file)
77
+ cli.should_receive(:unlink_file).exactly(cli.collection.linked.size).times
56
78
  cli.unlink
57
79
  end
58
80
  it "attempt to link one single file" do
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ module Dotify
4
+ describe Collection do
5
+
6
+ let(:collection) { Collection.new }
7
+ let(:home_files) {
8
+ [
9
+ @bashrc = double('unit1', :filename => '.bashrc', :linked? => false),
10
+ @gitconfig = double('unit2', :filename => '.gitconfig', :linked? => false),
11
+ @vimrc = double('unit3', :filename => '.vimrc', :linked? => true),
12
+ ]
13
+ }
14
+ describe "methods" do
15
+ %w[linked unlinked].each do |name|
16
+ it "should respond to #{name}" do
17
+ collection.should respond_to name
18
+ end
19
+ end
20
+ end
21
+
22
+ it "should pull the right files from List.home" do
23
+ files = [stub, stub, stub]
24
+ List.stub(:home).and_return files
25
+ collection.units.should == files
26
+ end
27
+
28
+ describe Collection, "#linked" do
29
+ before do
30
+ List.stub(:home).and_return home_files
31
+ end
32
+ let(:linked) { collection.linked }
33
+ it "should return the right Units" do
34
+ linked.should include @vimrc
35
+ linked.should_not include @gitconfig
36
+ linked.should_not include @bashrc
37
+ end
38
+ it "should yield the correct Units" do
39
+ expect { |b| collection.linked.each(&b) }.to yield_successive_args(*linked)
40
+ end
41
+ end
42
+
43
+ describe Collection, "#unlinked" do
44
+ before do
45
+ List.stub(:home).and_return home_files
46
+ end
47
+ let(:unlinked) { collection.unlinked }
48
+ it "should return the right Units" do
49
+ unlinked.should include @gitconfig
50
+ unlinked.should include @bashrc
51
+ unlinked.should_not include @vimrc
52
+ end
53
+ it "should yield the correct Units" do
54
+ expect { |b| collection.unlinked.each(&b) }.to yield_successive_args(*unlinked)
55
+ end
56
+ end
57
+
58
+ end
59
+ end
@@ -2,10 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  module Dotify
4
4
  describe Config do
5
- before {
6
- Config.unstub(:home)
7
- Thor::Util.stub(:user_home).and_return '/home/tmp'
8
- }
9
5
  describe Config, "#installed?" do
10
6
  it "should return true if Dotify has been setup" do
11
7
  File.should_receive(:exists?).with(Config.path).and_return(true)
@@ -23,6 +19,17 @@ module Dotify
23
19
  it "should return the home directory when called without a filename" do
24
20
  Config.home.should == Thor::Util.user_home
25
21
  end
22
+ it "should return the home directory with appended path" do
23
+ Config.home(".vimrc").should == '/tmp/home/.vimrc'
24
+ end
25
+ end
26
+ describe Config, "#path" do
27
+ it "should be able to show the dotify path when not passed any arguments" do
28
+ Config.path.should == '/tmp/home/.dotify'
29
+ end
30
+ it "should be able to show the dotify path" do
31
+ Config.path('.vimrc').should == '/tmp/home/.dotify/.vimrc'
32
+ end
26
33
  end
27
34
 
28
35
  describe "options" do
@@ -31,9 +38,6 @@ module Dotify
31
38
  { :ignore => { :dotfiles => %w[.gemrc], :dotify => %w[.gitmodule] } }
32
39
  end
33
40
  end
34
- it "should be able to show the dotify path" do
35
- Config.path.should == File.join(Config.home, '.dotify')
36
- end
37
41
  it "should set a default editor" do
38
42
  Config.editor.should == Config::EDITOR
39
43
  end
@@ -47,7 +51,7 @@ module Dotify
47
51
 
48
52
  describe Config, "#file" do
49
53
  it "should return the right page" do
50
- Config.file.should == '/home/tmp/.dotrc'
54
+ Config.file.should == '/tmp/home/.dotrc'
51
55
  end
52
56
  end
53
57
 
@@ -2,9 +2,10 @@ require 'spec_helper'
2
2
  require 'dotify/unit'
3
3
 
4
4
  class DummyUnit
5
- def dotfile
5
+ def home
6
6
  '.dummy'
7
7
  end
8
+ alias :dotfile :home
8
9
  def dotify
9
10
  '.dotify/.dummy'
10
11
  end
@@ -37,13 +38,13 @@ module Dotify
37
38
  subject.link.should == false
38
39
  end
39
40
  it "should copy the file from the home directory if it is not in Dotify" do
40
- FileUtils.should_receive(:rm_rf).with(subject.dotfile, :verbose => false)
41
- FileUtils.should_receive(:ln_sf).with(subject.dotify, subject.dotfile, :verbose => false)
41
+ FileUtils.should_receive(:rm_rf).with(subject.home, :verbose => false)
42
+ FileUtils.should_receive(:ln_sf).with(subject.dotify, subject.home, :verbose => false)
42
43
  subject.link
43
44
  end
44
45
  it "should simply remove the file from the home and relink it" do
45
46
  subject.stub(:in_dotify?) { false }
46
- FileUtils.should_receive(:cp_r).with(subject.dotfile, subject.dotify, :verbose => false)
47
+ FileUtils.should_receive(:cp_r).with(subject.home, subject.dotify, :verbose => false)
47
48
  FileUtils.stub(:rm_rf)
48
49
  FileUtils.stub(:ln_sf)
49
50
  subject.link
@@ -59,8 +60,8 @@ module Dotify
59
60
  end
60
61
  it "should call the right FileUtils methods" do
61
62
  subject.stub(:linked?) { true }
62
- FileUtils.should_receive(:rm_rf).with(subject.dotfile, :verbose => false)
63
- FileUtils.should_receive(:cp_r).with(subject.dotify, subject.dotfile, :verbose => false)
63
+ FileUtils.should_receive(:rm_rf).with(subject.home, :verbose => false)
64
+ FileUtils.should_receive(:cp_r).with(subject.dotify, subject.home, :verbose => false)
64
65
  FileUtils.should_receive(:rm_rf).with(subject.dotify, :verbose => false)
65
66
  subject.unlink
66
67
  end
@@ -74,15 +75,14 @@ module Dotify
74
75
  it { should respond_to :filename }
75
76
  it { should respond_to :dotify }
76
77
  it { should respond_to :dotfile }
78
+ it { should respond_to :home }
77
79
  it { should respond_to :linked? }
78
80
  it { should respond_to :linked }
79
- it { should respond_to :added? }
80
- it { should respond_to :added }
81
81
 
82
82
  it "should set the attributes properly" do
83
83
  unit.filename.should == '.vimrc'
84
84
  unit.dotify.should == '/tmp/home/.dotify/.vimrc'
85
- unit.dotfile.should == '/tmp/home/.vimrc'
85
+ unit.home.should == '/tmp/home/.vimrc'
86
86
  end
87
87
  it "should puts the filename" do
88
88
  unit.to_s.should == unit.filename
@@ -92,11 +92,11 @@ module Dotify
92
92
  describe "existence in directories" do
93
93
  let(:unit) { Unit.new(".bashrc") }
94
94
  it "should check for the existence in the home directory" do
95
- File.stub(:exists?).with(unit.dotfile).and_return true
95
+ File.stub(:exists?).with(unit.home).and_return true
96
96
  unit.in_home_dir?.should == true
97
97
  end
98
98
  it "should return false if the file is not in the home directory" do
99
- File.stub(:exists?).with(unit.dotfile).and_return false
99
+ File.stub(:exists?).with(unit.home).and_return false
100
100
  unit.in_home_dir?.should_not == true
101
101
  end
102
102
  it "should check for the existence of the file in Dotify" do
@@ -120,7 +120,7 @@ module Dotify
120
120
  unit.linked_to_dotify?.should be_true
121
121
  end
122
122
  it "should return false if the dotfile is not linked to the Dotify file" do
123
- File.stub(:readlink).with(unit.dotfile).and_return '/tmp/home/.another_file'
123
+ File.stub(:readlink).with(unit.home).and_return '/tmp/home/.another_file'
124
124
  unit.linked_to_dotify?.should be_false
125
125
  end
126
126
  end
@@ -140,29 +140,14 @@ module Dotify
140
140
  end
141
141
  end
142
142
 
143
- describe Unit, "#added?" do
144
- let(:unit) { Unit.new(".added") }
145
- before do
146
- unit.stub(:in_dotify?).and_return true # stub dotify file exist check
147
- end
148
- it "should return true if all checks work" do
149
- unit.stub(:linked_to_dotify?).and_return false # stub identical file check
150
- unit.should be_added
151
- end
152
- it "should return false if one or more checks fail" do
153
- unit.stub(:linked_to_dotify?).and_return true # stub identical file check
154
- unit.should_not be_added
155
- end
156
- end
157
-
158
143
  describe Unit, "#symlink" do
159
144
  let!(:unit) { Unit.new(".symlinked") }
160
145
  it "should return the symlink for the file" do
161
- File.should_receive(:readlink).with(unit.dotfile).once
146
+ File.should_receive(:readlink).with(unit.home).once
162
147
  unit.symlink
163
148
  end
164
149
  it "should return NoSymlink if error or no symlink" do
165
- File.stub(:readlink).with(unit.dotfile).and_raise(StandardError)
150
+ File.stub(:readlink).with(unit.home).and_raise(StandardError)
166
151
  expect { unit.symlink }.not_to raise_error
167
152
  unit.symlink.should == NoSymlink
168
153
  end
@@ -14,6 +14,11 @@ RSpec.configure do |config|
14
14
  config.filter_run :focus
15
15
 
16
16
  config.before(:each) do
17
- Dotify::Config.stub(:home) { '/tmp/home' }
17
+ class Thor
18
+ module Util
19
+ end
20
+ end
21
+ Thor::Util.stub(:user_home) { '/tmp/home' }
22
+ #Dotify::Config.stub(:home) { '/tmp/home' }
18
23
  end
19
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-06 00:00:00.000000000 Z
12
+ date: 2012-07-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -159,18 +159,16 @@ files:
159
159
  - dotify.gemspec
160
160
  - lib/dotify.rb
161
161
  - lib/dotify/cli.rb
162
+ - lib/dotify/collection.rb
162
163
  - lib/dotify/config.rb
163
164
  - lib/dotify/errors.rb
164
- - lib/dotify/files.rb
165
- - lib/dotify/git.rb
166
165
  - lib/dotify/list.rb
167
166
  - lib/dotify/unit.rb
168
167
  - lib/dotify/version.rb
169
168
  - lib/dotify/version_checker.rb
170
169
  - spec/dotify/cli_spec.rb
170
+ - spec/dotify/collection_spec.rb
171
171
  - spec/dotify/config_spec.rb
172
- - spec/dotify/files_spec.rb
173
- - spec/dotify/git_spec.rb
174
172
  - spec/dotify/list_spec.rb
175
173
  - spec/dotify/unit_spec.rb
176
174
  - spec/dotify/version_checker_spec.rb
@@ -207,9 +205,8 @@ specification_version: 3
207
205
  summary: A CLI Tool for managing your dotfiles
208
206
  test_files:
209
207
  - spec/dotify/cli_spec.rb
208
+ - spec/dotify/collection_spec.rb
210
209
  - spec/dotify/config_spec.rb
211
- - spec/dotify/files_spec.rb
212
- - spec/dotify/git_spec.rb
213
210
  - spec/dotify/list_spec.rb
214
211
  - spec/dotify/unit_spec.rb
215
212
  - spec/dotify/version_checker_spec.rb
@@ -1,66 +0,0 @@
1
- require 'thor/actions'
2
- require 'thor/shell'
3
-
4
- Dotify::Config.load_config!
5
-
6
- module Dotify
7
- class Files
8
- class << self
9
- # All
10
- #
11
- # Pulls an array of Units from the home
12
- # directory.
13
- def all
14
- @all ||= List.home
15
- end
16
-
17
- # Linked files are those files which have a
18
- # symbolic link pointing to the Dotify file.
19
- def linked
20
- links = self.all.select { |f| f.linked? }
21
- return links unless block_given?
22
- links.each {|u| yield u }
23
- end
24
-
25
- # Unlinked files are, of course, the opposite
26
- # of linked files. These are Dotify files which
27
- # Have no home dir files that are linked to them.
28
- def unlinked
29
- unl = self.all.select { |f| !f.linked? }
30
- return unl unless block_given?
31
- unl.each {|u| yield u }
32
- end
33
-
34
- # Uninstalled dotfiles are the dotfiles in the home
35
- # directory that have not been loaded into Dotify or
36
- # linked to the corresponding Dotify path.
37
- def uninstalled
38
- uni = self.all.select { |f| !f.added? && !f.linked? }
39
- return uni unless block_given?
40
- uni.each {|u| yield u }
41
- end
42
-
43
- def filename(file)
44
- File.basename(file)
45
- end
46
-
47
- def dotfile(file = nil)
48
- file.nil? ? Config.home : File.join(Config.home, filename(file))
49
- end
50
- alias :home :dotfile
51
-
52
- def dotify(file = nil)
53
- file.nil? ? Config.path : File.join(Config.path, filename(file))
54
- end
55
-
56
- def link_dotfile(file)
57
- FileUtils.ln_s(filename(file), Config.home) == 0 ? true : false
58
- end
59
-
60
- def unlink_dotfile(file)
61
- FileUtils.rm_rf dotfile(file)
62
- end
63
-
64
- end
65
- end
66
- end
@@ -1,22 +0,0 @@
1
- require 'dotify/config'
2
-
3
- module Dotify
4
- class Git
5
-
6
- # extend ::Git
7
-
8
- # class << self
9
-
10
- # def repo
11
- # @repo ||= git.open(Config.path)
12
- # end
13
-
14
- # private
15
-
16
- # def git
17
- # ::Git
18
- # end
19
-
20
- # end
21
- end
22
- end
@@ -1,116 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Dotify
4
- describe Files do
5
-
6
- let(:home_files) {
7
- [
8
- @bashrc = double('unit1', :filename => '.bashrc', :added? => true, :linked? => false),
9
- @gitconfig = double('unit2', :filename => '.gitconfig', :added? => false, :linked? => false),
10
- @vimrc = double('unit3', :filename => '.vimrc', :added? => true, :linked? => true),
11
- ]
12
- }
13
- describe "methods" do
14
- %w[all linked unlinked uninstalled].each do |name|
15
- it "should respond to #{name}" do
16
- Files.should respond_to name
17
- end
18
- end
19
- end
20
-
21
- describe Files, "#all" do
22
- it "should pull the right files from List.home" do
23
- files = [stub, stub, stub]
24
- List.stub(:home).and_return files
25
- Files.all.should == files
26
- end
27
- end
28
-
29
- describe Files, "#linked" do
30
- before do
31
- Files.stub(:all).and_return home_files
32
- end
33
- let(:filenames) { Files.linked }
34
- it "should return the right Units" do
35
- filenames.should include @vimrc
36
- filenames.should_not include @gitconfig
37
- filenames.should_not include @bashrc
38
- end
39
- it "should yield the correct Units" do
40
- expect { |b| Files.linked(&b) }.to yield_successive_args(*filenames)
41
- end
42
- end
43
-
44
- describe Files, "#unlinked" do
45
- before do
46
- Files.stub(:all).and_return home_files
47
- end
48
- let(:filenames) { Files.unlinked }
49
- it "should return the right Units" do
50
- filenames.should include @gitconfig
51
- filenames.should include @bashrc
52
- filenames.should_not include @vimrc
53
- end
54
- it "should yield the correct Units" do
55
- expect { |b| Files.unlinked(&b) }.to yield_successive_args(*filenames)
56
- end
57
- end
58
-
59
- describe Files, "#uninstalled" do
60
- before do
61
- Files.stub(:all).and_return home_files
62
- end
63
- let(:filenames) { Files.uninstalled }
64
- it "should return the right Units" do
65
- filenames.should include @gitconfig
66
- filenames.should_not include @bashrc
67
- filenames.should_not include @vimrc
68
- end
69
- it "should yield the correct Units" do
70
- expect { |b| Files.uninstalled(&b) }.to yield_successive_args(*filenames)
71
- end
72
- end
73
-
74
- it "should split a filename correct" do
75
- Files.filename("some/random/path/to/file.txt").should == 'file.txt'
76
- Files.filename("another/path/no_extension").should == 'no_extension'
77
- end
78
-
79
- describe Files, "#home" do
80
- it "should point to the home directory" do
81
- Files.home.should == '/tmp/home'
82
- end
83
- it "should return a absolute path to the file in the home directory" do
84
- Files.home(".vimrc").should == '/tmp/home/.vimrc'
85
- Files.home("/spec/home/.bashrc").should == '/tmp/home/.bashrc'
86
- end
87
- end
88
-
89
- describe Files, "#dotify" do
90
- it "should point to the Dotify directory" do
91
- Files.dotify.should == '/tmp/home/.dotify'
92
- end
93
- it "should return a absolute path to the file in Dotify" do
94
- Files.dotify(".vimrc").should == '/tmp/home/.dotify/.vimrc'
95
- Files.dotify("/spec/home/.bashrc").should == '/tmp/home/.dotify/.bashrc'
96
- end
97
- end
98
-
99
- describe Files, "#link_dotfile" do
100
- it "should receive a file and link it into the root path" do
101
- first = File.join(Config.path, ".vimrc")
102
- FileUtils.should_receive(:ln_s).with(Files.filename(first), Config.home).once
103
- Files.link_dotfile first
104
- end
105
- end
106
-
107
- describe Files, "#unlink_dotfile" do
108
- it "should receive a file and remove it from the root" do
109
- first = "/spec/test/.file"
110
- FileUtils.stub(:rm_rf).with(File.join(Config.home, Files.filename(first))).once
111
- Files.unlink_dotfile first
112
- FileUtils.unstub(:rm_rf)
113
- end
114
- end
115
- end
116
- end
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
- require 'dotify/git'
3
-
4
- describe Dotify::Git do
5
- end