dotman 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 029ccdbd5f8735d588b07d1b231dbbdcfa52bcf5
4
- data.tar.gz: 942ab9df1f7fac57a7aecc289070eea870c6347c
3
+ metadata.gz: fd8b469fcc0d6da51b7488b195248ecccd4b8d74
4
+ data.tar.gz: 462ec000404811976fdfff032020270d3b6e1251
5
5
  SHA512:
6
- metadata.gz: 143f6aa72b1e6a9ee3fdfcf1155a39a19136bfc1807866654c5ac96416d475890ab909968e227cc83edcbf0c914721a5103fa9cd1a1c4f790ba3644afaf60e15
7
- data.tar.gz: 3bd1891733832b7717afe57ccd093349b4d91bb777efebb3891ce4b6a32c49bfaedb810799368da024396cf1d0f7b188f90fa67490ede57b45fa37ac23e87ee5
6
+ metadata.gz: 53852745e415c58ca8bf1262088ce74b0f708434f1336588487e5ed742b6515b77d685997b673576a8f2891eeb70e0d42356f5fd527fdb9deeac2f806d9460de
7
+ data.tar.gz: ef869344289cfbe23a4ec377e552fb71e2e3ad8a4de9ae649ac4a9b636debeffd450eb06e1424df0f1a6db5f1775c7c28fef3eccfa9804b620e3b583170df265
data/README.md CHANGED
@@ -1,24 +1,8 @@
1
1
  # Dotman
2
2
 
3
- TODO: Write a gem description
3
+ This is a work in progress. It is not yet in working condition.
4
4
 
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'dotman'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install dotman
18
-
19
- ## Usage
20
-
21
- TODO: Write usage instructions here
5
+ This gem will allow you to switch between different dotfiles on the same user account.
22
6
 
23
7
  ## Contributing
24
8
 
data/bin/dot ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH << File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'rubygems'
5
+ require 'dotman'
6
+
7
+ case ARGV.first
8
+ when 'clone'
9
+ Dotman::Base.ensure_dotman_folder_exists
10
+ Dotman::Git.klone(ARGV[1], ARGV[2])
11
+ when 'use'
12
+ Dotman::User.set(ARGV[1])
13
+ end
data/lib/dotman.rb CHANGED
@@ -1,9 +1,7 @@
1
+ require 'fileutils'
1
2
  require "dotman/version"
2
- require 'git'
3
- module Dotman
4
- def self.ensure_dotman_folder_exists
5
- unless File.directory?("#{ENV['HOME']}/.dotman")
6
- FileUtils.mkdir("#{ENV['HOME']}/.dotman")
7
- end
8
- end
9
- end
3
+ require "dotman/base"
4
+ require "dotman/git"
5
+ require "dotman/dotfile_collection"
6
+ require "dotman/user"
7
+
@@ -0,0 +1,40 @@
1
+ module Dotman
2
+ class Base
3
+
4
+ def self.default_folder
5
+ "#{ENV['HOME']}/.dotman/default"
6
+ end
7
+
8
+ def self.dotman_folder
9
+ "#{ENV['HOME']}/.dotman"
10
+ end
11
+
12
+ def self.current_dotman
13
+ File.join(ENV['HOME'], '.dotman', '.current')
14
+ end
15
+
16
+ def self.ensure_dotman_folder_exists
17
+ unless File.directory?(dotman_folder)
18
+ FileUtils.mkdir(dotman_folder)
19
+ end
20
+ end
21
+
22
+ def self.ensure_default_folder_exists
23
+ unless File.directory?(default_folder)
24
+ FileUtils.mkdir_p(default_folder)
25
+ end
26
+ end
27
+
28
+ def self.ensure_current_dotman_file_exists
29
+ unless File.exist?(current_dotman)
30
+ File.open(current_dotman, 'w') do |f|
31
+ f.write('default')
32
+ end
33
+ end
34
+ end
35
+ ensure_dotman_folder_exists
36
+ ensure_default_folder_exists
37
+ ensure_current_dotman_file_exists
38
+
39
+ end
40
+ end
@@ -0,0 +1,47 @@
1
+ module Dotman
2
+
3
+ DOTFILES_PATH = "#{ENV['HOME']}/.dotman/dotfiles.yml"
4
+ DOTFILES_YAML = File.exist?(DOTFILES_PATH) ? YAML::load_file(DOTFILES_PATH) : Hash.new
5
+
6
+ class DotfileCollection
7
+
8
+ attr_accessor :yaml
9
+
10
+ def self.find_by_alias(alias_name)
11
+ dotfile_collection = new
12
+ ensure_default_dotfile_configuration_exists
13
+ dotfile_collection.yaml = DOTFILES_YAML.fetch(alias_name) if DOTFILES_YAML
14
+ dotfile_collection
15
+ end
16
+
17
+ def self.new_configuration(folder_name, alias_name = nil)
18
+ dotfile_collection = new
19
+ alias_name = folder_name unless alias_name
20
+ DOTFILES_YAML.store(alias_name, {
21
+ 'folder_name' => folder_name
22
+ }
23
+ )
24
+ save_dotfile_yaml
25
+ dotfile_collection.yaml = DOTFILES_YAML
26
+ dotfile_collection
27
+ end
28
+
29
+
30
+ def all_dotfiles
31
+ Dir.entries("#{Dotman::Base.dotman_folder}/#{@yaml['folder_name']}").select{|x| x =~ /\.{1}\w+/ }
32
+ end
33
+
34
+ private
35
+
36
+ def self.ensure_default_dotfile_configuration_exists
37
+ unless DOTFILES_YAML && DOTFILES_YAML['default']
38
+ new_configuration('default')
39
+ end
40
+ end
41
+
42
+ def self.save_dotfile_yaml
43
+ File.open(DOTFILES_PATH, 'w') { |f| f.write DOTFILES_YAML.to_yaml }
44
+ end
45
+
46
+ end
47
+ end
data/lib/dotman/git.rb ADDED
@@ -0,0 +1,23 @@
1
+ module Dotman
2
+ class Git
3
+ def self.klone(git_location, alias_name = nil)
4
+ unless git_location.nil?
5
+ clone_repository(git_location, alias_name)
6
+ end
7
+ end
8
+
9
+ def self.folder_name(git_location)
10
+ folder_name = git_location.scan(/[^:]+[\/]?dotfile[s?]{1}/).first.gsub('/', '_')
11
+ end
12
+
13
+ def self.clone_repository(git_location, alias_name = nil)
14
+ dotfile_location = "#{ENV['HOME']}/.dotman/#{folder_name(git_location)}"
15
+ if (File.directory?(dotfile_location))
16
+ STDOUT.puts("Dotfiles were already cloned")
17
+ else
18
+ system "git clone #{git_location} #{dotfile_location}"
19
+ Dotman::DotfileCollection.new_configuration(folder_name(git_location), alias_name)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,68 @@
1
+ module Dotman
2
+ class User
3
+ def initialize(shortcut)
4
+ @alias = shortcut
5
+ @collection = Dotman::DotfileCollection.find_by_alias(shortcut)
6
+ @folder_name = @collection.yaml['folder_name']
7
+ end
8
+
9
+ attr_reader :alias, :folder_name, :collection
10
+
11
+ def move_home_files_to_default
12
+ @collection.all_dotfiles.each do |file|
13
+ if File.exist?("#{ENV['HOME']}/#{file}")
14
+ FileUtils.mv("#{ENV['HOME']}/#{file}", Dotman::Base.default_folder)
15
+ end
16
+ end
17
+ end
18
+
19
+ def self.move_default_back_to_home
20
+ $default_user.collection.all_dotfiles.each do |file|
21
+ FileUtils.mv(Dotman::Base.default_folder + '/' + file, ENV['HOME'] )
22
+ end
23
+ end
24
+
25
+ def symlink_dotfiles
26
+ @collection.all_dotfiles.each do |file|
27
+ FileUtils.ln_s(File.join(Dotman::Base.dotman_folder, @folder_name, file), File.join(ENV['HOME'], file))
28
+ end
29
+ end
30
+
31
+ def remove_symlink_dotfiles
32
+ @collection.all_dotfiles.each do |file|
33
+ if File.symlink?(File.join(ENV['HOME'], file))
34
+ FileUtils.rm(File.join(ENV['HOME'], file))
35
+ end
36
+ end
37
+ end
38
+
39
+ def self.set(shortcut)
40
+ current.remove_symlink_dotfiles
41
+ move_default_back_to_home
42
+ set_user = new(shortcut)
43
+ set_user.move_home_files_to_default
44
+ set_user.symlink_dotfiles
45
+ set_user.set_current_user
46
+ end
47
+
48
+
49
+
50
+ def self.current
51
+ new(current_user_alias)
52
+ end
53
+
54
+ def set_current_user
55
+ File.open(Dotman::Base.current_dotman, 'w') do |f|
56
+ f.write(@alias)
57
+ end
58
+ end
59
+
60
+
61
+ def self.current_user_alias
62
+ File.open(Dotman::Base.current_dotman).read.strip
63
+ end
64
+
65
+ $default_user = new('default')
66
+
67
+ end
68
+ end
@@ -1,3 +1,3 @@
1
1
  module Dotman
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ describe Dotman::Base do
3
+ let (:dotfiles_folder) { File.expand_path('../../data/dotfiles', __FILE__) }
4
+ let!(:dotfiles) {FileUtils.touch "#{dotfiles_folder}/.vimrc"; FileUtils.touch "#{dotfiles_folder}/.bashrc"; FileUtils.touch "#{dotfiles_folder}/.zshrc" }
5
+
6
+ describe ".ensure_dotman_folder_exists" do
7
+ context "when `$HOME.dotman/` does not exist" do
8
+ it "creates the dotman directory" do
9
+ File.stub(:directory?).and_return(false)
10
+ FileUtils.should_receive(:mkdir).with("#{ENV['HOME']}/.dotman")
11
+ Dotman::Base.ensure_dotman_folder_exists
12
+ end
13
+ end
14
+
15
+ context "when $HOME.dotman/ exists" do
16
+ it "does nothing" do
17
+ File.stub(:directory?).and_return(true)
18
+ FileUtils.should_not_receive(:mkdir)
19
+ Dotman::Base.ensure_dotman_folder_exists
20
+ end
21
+ end
22
+ end
23
+
24
+ describe ".all_dotfiles" do
25
+ context "when dotfiles exist for a location" do
26
+
27
+ it "returns all the dotfiles" do
28
+ Dotman::Base.all_dotfiles(dotfiles_folder).should include('.vimrc', '.bashrc', '.zshrc')
29
+ end
30
+
31
+ it "should not contain . or .." do
32
+ Dotman::Base.all_dotfiles(dotfiles_folder).should_not include('..', '.')
33
+ end
34
+
35
+ it "does not contain non dotfiles" do
36
+ Dotman::Base.all_dotfiles(dotfiles_folder).should_not include('some_nondot_file')
37
+ end
38
+
39
+ end
40
+ end
41
+
42
+ describe ".move_home_files_to_default" do
43
+ context "when having dotfiles in project" do
44
+ it "moves the files" do
45
+ Dotman::Base.move_home_files_to_default(dotfiles_folder)
46
+ Dir.entries(Dotman::Base.default_folder).should include('.vimrc', '.bashrc', '.zshrc')
47
+ end
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ describe Dotman::DotfileCollection do
3
+ describe ".find_by_alias" do
4
+ context "default folder doesnt exist" do
5
+ it 'creates the default folder' do
6
+ Dotman::DotfileCollection.find_by_alias('default')
7
+ end
8
+ end
9
+ end
10
+ end
data/spec/dotman_spec.rb CHANGED
@@ -1,20 +1,3 @@
1
1
  require 'spec_helper'
2
2
  describe Dotman do
3
- describe "::ensure_dotman_folder_exists" do
4
- context "$HOME.dotman/ does not exist" do
5
- it "creates the dotman directory" do
6
- File.stub(:directory?).and_return(true)
7
- FileUtils.should_receive(:mkdir).with("$HOME/.dotman")
8
- Dotman.ensure_dotman_folder_exists
9
- end
10
- end
11
-
12
- context "$HOME.dotman/ already exists" do
13
- it "does nothing" do
14
- File.stub(:directory?).and_return(false)
15
- FileUtils.should_not_receive(:mkdir).with("$HOME/.dotman")
16
- Dotman.ensure_dotman_folder_exists
17
- end
18
- end
19
- end
20
3
  end
data/spec/git_spec.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
- describe Git do
2
+ describe Dotman::Git do
3
3
  describe ".folder_name" do
4
4
  it "returns the folder name of the git repo" do
5
- Git.folder_name('git@github.com:Timbinous/dotfiles.git').should == "Timbinous_dotfiles"
5
+ Dotman::Git.folder_name('git@github.com:Timbinous/dotfiles.git').should == "Timbinous_dotfiles"
6
6
  end
7
7
  end
8
8
 
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ describe Dotman::DotfileCollection do
3
+ describe ".find_by_alias" do
4
+ context "when dotfile collection is found" do
5
+ let (:alias_name) { 'tim' }
6
+ let (:dotfile_collection_name) { 'Timbinous_dotfiles' }
7
+ let! (:dotfile_configuration) { Dotman::DotfileCollection.new_configuration(dotfile_collection_name, alias_name) }
8
+ it "returns the dotfile collection" do
9
+ Dotman::DotfileCollection.find_by_alias(alias_name)['folder_name'].should == dotfile_collection_name
10
+ end
11
+ end
12
+ end
13
+ after :all do
14
+ FileUtils.rm_r("#{ENV['HOME']}/.dotman/dotfiles.yml")
15
+ end
16
+ end
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
- describe Dotman do
3
- context "dotman folder doesn't exist on the folder" do
2
+ describe Dotman::Base do
3
+ context "when .dotman folder doesn't exist in the home directory" do
4
4
  before :all do
5
5
  FileUtils.rm_rf("#{ENV['HOME']}/.dotman")
6
6
  end
7
7
 
8
8
  it "creates a new folder" do
9
9
  File.directory?("#{ENV['HOME']}/.dotman").should == false
10
- Dotman.ensure_dotman_folder_exists
10
+ Dotman::Base.ensure_dotman_folder_exists
11
11
  File.directory?("#{ENV['HOME']}/.dotman").should == true
12
12
  end
13
13
 
@@ -3,20 +3,54 @@
3
3
  #
4
4
  #
5
5
  require 'spec_helper'
6
- describe Git do
6
+ describe Dotman::Git do
7
7
  before :all do
8
- Dotman.ensure_dotman_folder_exists
9
- FileUtils.rm_rf("#{ENV['HOME']}/.dotman/Timbinous_dotfiles")
8
+ Dotman::Base.ensure_dotman_folder_exists
10
9
  end
11
10
 
12
11
  context "cloning a new repo" do
13
- before :each do
12
+
13
+ let (:git_dotfile_repo_path) { "git@github.com:Timbinous/dotfiles.git" }
14
+ let (:git_folder_name) { Dotman::Git.folder_name(git_dotfile_repo_path) }
15
+
16
+ context "when no alias passed" do
17
+
18
+ it "clones to the $HOME/.dotman folder" do
19
+ expect {
20
+ Dotman::Git.clone_repository(git_dotfile_repo_path) }.
21
+ to change { File.directory?("#{ENV['HOME']}/.dotman/Timbinous_dotfiles") }.to true
22
+ end
23
+
24
+ it "sets the yaml configuration" do
25
+ Dotman::DotfileCollection.find_by_alias(git_folder_name).should_not be_false
26
+ end
27
+
28
+ after :all do
29
+ FileUtils.rm_r("#{ENV['HOME']}/.dotman/dotfiles.yml")
30
+ FileUtils.rm_rf("#{ENV['HOME']}/.dotman/Timbinous_dotfiles")
31
+ end
32
+
14
33
  end
15
- it "clones to the $HOME/.dotman folder" do
16
- expect {
17
- Git.clone_repository("git@github.com:Timbinous/dotfiles.git") }.
18
- to change { File.directory?("#{ENV['HOME']}/.dotman/Timbinous_dotfiles") }.to true
34
+
35
+ context "when alias was passed" do
36
+
37
+ it "clones to the $HOME/.dotman folder" do
38
+ expect {
39
+ Dotman::Git.clone_repository(git_dotfile_repo_path, 'tim') }.
40
+ to change { File.directory?("#{ENV['HOME']}/.dotman/Timbinous_dotfiles") }.to true
41
+ end
42
+
43
+ it "sets the yaml configuration" do
44
+ Dotman::DotfileCollection.find_by_alias('tim').should_not be_false
45
+ end
46
+
47
+ after :all do
48
+ FileUtils.rm_r("#{ENV['HOME']}/.dotman/dotfiles.yml")
49
+ FileUtils.rm_rf("#{ENV['HOME']}/.dotman/Timbinous_dotfiles")
50
+ end
51
+
19
52
  end
20
53
  end
54
+
21
55
 
22
56
  end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+ describe Dotman::User do
3
+ describe ".current_user_alias" do
4
+ before :all do
5
+ File.open(Dotman::Base.current_dotman, 'w') { |f| f.write 'tim' }
6
+ end
7
+
8
+ it 'returns the alias of the current user' do
9
+ Dotman::User.current_user_alias.should == 'tim'
10
+ end
11
+ end
12
+
13
+ describe "#set_current_user" do
14
+ let (:user) { Dotman::User.new('frank') }
15
+
16
+ before :all do
17
+ Dotman::DotfileCollection.new_configuration('frankie_dotfiles', 'frank')
18
+ end
19
+
20
+ it 'writes to the .current file, the alias of the current user' do
21
+ user.set_current_user
22
+ Dotman::User.current_user_alias.should == 'frank'
23
+ end
24
+ end
25
+
26
+
27
+ describe ".current" do
28
+
29
+ it 'returns the current users information' do
30
+ Dotman::User.current.folder_name.should == 'frankie_dotfiles'
31
+ end
32
+ end
33
+
34
+ describe "#set" do
35
+
36
+ before :each do
37
+ Dotman::Git.clone_repository("git@github.com:Timbinous/dotfiles.git", 'tim')
38
+ FileUtils.touch(["#{ENV['HOME']}/.vimrc", "#{ENV['HOME']}/.zshrc", "#{ENV['HOME']}/.bashrc"])
39
+ Dotman::User.set('tim')
40
+ end
41
+
42
+ context "when not the current user" do
43
+ it "moves the default dotfiles over to the default folder" do
44
+ $default_user.collection.all_dotfiles.should_not be_empty
45
+ end
46
+
47
+ it "symlinks your dotfiles to the home directory" do
48
+ File.symlink?(File.join(ENV['HOME'], '.zshrc')).should be_true
49
+ File.symlink?(File.join(ENV['HOME'], '.vimrc')).should be_true
50
+ File.symlink?(File.join(ENV['HOME'], '.bashrc')).should be_true
51
+ end
52
+ end
53
+
54
+ after :each do
55
+ FileUtils.rm_r("#{ENV['HOME']}/.dotman/dotfiles.yml")
56
+ FileUtils.rm_rf("#{ENV['HOME']}/.dotman/Timbinous_dotfiles")
57
+ $default_user.collection.all_dotfiles.each do |df|
58
+ FileUtils.rm("#{ENV['HOME']}/.dotman/default/#{df}")
59
+ end
60
+ end
61
+ end
62
+ end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,2 @@
1
+ ENV['HOME'] = File.expand_path('../data/home', __FILE__)
1
2
  require_relative '../lib/dotman.rb'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotman
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
  - Tim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-25 00:00:00.000000000 Z
11
+ date: 2013-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -69,7 +69,8 @@ dependencies:
69
69
  description: Dotfiles Manager
70
70
  email:
71
71
  - timbinous@gmail.com
72
- executables: []
72
+ executables:
73
+ - dot
73
74
  extensions: []
74
75
  extra_rdoc_files: []
75
76
  files:
@@ -79,14 +80,26 @@ files:
79
80
  - LICENSE.txt
80
81
  - README.md
81
82
  - Rakefile
83
+ - bin/dot
82
84
  - dotman.gemspec
83
85
  - lib/dotman.rb
86
+ - lib/dotman/base.rb
87
+ - lib/dotman/dotfile_collection.rb
88
+ - lib/dotman/git.rb
89
+ - lib/dotman/user.rb
84
90
  - lib/dotman/version.rb
85
- - lib/git.rb
91
+ - spec/data/dotfiles/.bashrc
92
+ - spec/data/dotfiles/.vimrc
93
+ - spec/data/dotfiles/.zshrc
94
+ - spec/data/dotfiles/some_nondot_file
95
+ - spec/dotman/base_spec.rb
96
+ - spec/dotman/dotfile_collection_spec.rb
86
97
  - spec/dotman_spec.rb
87
98
  - spec/git_spec.rb
88
- - spec/integration/dotman_integration_spec.rb
99
+ - spec/integration/dotfile_collection_integration_spec.rb
100
+ - spec/integration/dotman_base_integration_spec.rb
89
101
  - spec/integration/git_integration_spec.rb
102
+ - spec/integration/user_integration_spec.rb
90
103
  - spec/spec_helper.rb
91
104
  homepage: ''
92
105
  licenses:
@@ -114,8 +127,16 @@ specification_version: 4
114
127
  summary: Use this utility to manage your dotfiles and others who may use the same
115
128
  login user as yourself
116
129
  test_files:
130
+ - spec/data/dotfiles/.bashrc
131
+ - spec/data/dotfiles/.vimrc
132
+ - spec/data/dotfiles/.zshrc
133
+ - spec/data/dotfiles/some_nondot_file
134
+ - spec/dotman/base_spec.rb
135
+ - spec/dotman/dotfile_collection_spec.rb
117
136
  - spec/dotman_spec.rb
118
137
  - spec/git_spec.rb
119
- - spec/integration/dotman_integration_spec.rb
138
+ - spec/integration/dotfile_collection_integration_spec.rb
139
+ - spec/integration/dotman_base_integration_spec.rb
120
140
  - spec/integration/git_integration_spec.rb
141
+ - spec/integration/user_integration_spec.rb
121
142
  - spec/spec_helper.rb
data/lib/git.rb DELETED
@@ -1,17 +0,0 @@
1
- class Git
2
- def self.klone(git_location)
3
- # clone_repository(git_location)
4
- end
5
-
6
- def self.folder_name(git_location)
7
- folder_name = git_location.scan(/[^:]+[\/]?dotfile[s?]{1}/).first.gsub('/', '_')
8
- end
9
-
10
- def self.clone_repository(git_location)
11
- if (File.directory?("#{ENV['HOME']}/.dotman/#{folder_name(git_location)}"))
12
- STDOUT.puts("Dotfiles were already cloned")
13
- else
14
- system "git clone #{git_location} #{ENV['HOME']}/.dotman/#{folder_name(git_location)}"
15
- end
16
- end
17
- end