dotify 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby -*-
3
+
4
+ $:.unshift File.expand_path("../../lib", __FILE__)
5
+ require 'dotify/cli'
6
+ Dotify::CLI.start
@@ -17,4 +17,5 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency "thor"
19
19
  gem.add_dependency "rake"
20
+ gem.add_development_dependency "rspec"
20
21
  end
@@ -1,5 +1,6 @@
1
- require "dotify/version"
2
-
3
1
  module Dotify
4
- # Your code goes here...
5
2
  end
3
+
4
+ require "thor"
5
+ require "fileutils"
6
+ require "dotify/version"
@@ -0,0 +1,107 @@
1
+ require 'thor'
2
+ require 'thor/util'
3
+ require 'dotify'
4
+ require 'dotify/version'
5
+ require 'erb'
6
+ require 'fileutils'
7
+
8
+ module Dotify
9
+ class CLI < Thor
10
+ include Thor::Actions
11
+ default_task :help
12
+
13
+ map "-l" => "link"
14
+ map "-u" => "unlink"
15
+ map "-b" => "backup"
16
+ map "-r" => "restore"
17
+
18
+ DOTIFY_DIR_NAME = ENV['DOTIFY_DIR_NAME'] || '.dotify'
19
+ DOTIFY_PATH = ENV['DOTIFY_PATH'] || "#{Thor::Util.user_home}/#{DOTIFY_DIR_NAME}"
20
+
21
+ def self.source_root
22
+ DOTIFY_PATH
23
+ end
24
+
25
+ desc :setup, "Get your system setup for dotfile management"
26
+ def setup
27
+ ::FileUtils.mkdir_p DOTIFY_PATH
28
+ end
29
+
30
+ desc :link, "Link up your dotfiles"
31
+ method_option :force, default: false, type: :boolean, aliases: '-f', desc: "Definitely remove all dotfiles"
32
+ def link
33
+ dotfile_list do |file|
34
+ if template? file
35
+ template file, dotfile_location(no_extension(filename(file)))
36
+ else
37
+ if options.force?
38
+ replace_link dotfile_location(file), file
39
+ else
40
+ create_link dotfile_location(file), file
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ desc :unlink, "Unlink individual dotfiles"
47
+ method_option :force, default: false, type: :boolean, aliases: '-f', desc: "Definitely remove all dotfiles"
48
+ def unlink
49
+ dotfile_list do |file|
50
+ destination = filename(file)
51
+ if options.force? || yes?("Are you sure you want to remove ~/#{destination}? [Yn]", :blue)
52
+ remove_file dotfile_location(file), verbose: true
53
+ end
54
+ end
55
+ end
56
+
57
+ desc :backup, "Backup your dotfiles for quick recovery if something goes wrong"
58
+ def backup
59
+ end
60
+
61
+ desc :restore, "Restore your backed-up dotfiles"
62
+ def restore
63
+ end
64
+
65
+ no_tasks do
66
+
67
+ def dotfile_location(file)
68
+ "#{home}/#{filename(file)}"
69
+ end
70
+
71
+ def no_extension(file)
72
+ file = file.split('.')
73
+ file.pop
74
+ file.join('.')
75
+ end
76
+
77
+ def home
78
+ Thor::Util.user_home
79
+ end
80
+
81
+ def replace_link(dotfile, file)
82
+ remove_file dotfile
83
+ create_link dotfile, file
84
+ end
85
+
86
+ def dotfile_list
87
+ files = Dir["#{DOTIFY_PATH}/.*"]
88
+ files.delete_if { |f| File.directory? f }
89
+ if block_given?
90
+ files.each { |f| yield f }
91
+ else
92
+ files
93
+ end
94
+ end
95
+
96
+ def filename(file)
97
+ file.split("/").last
98
+ end
99
+
100
+ def template?(file)
101
+ filename(file).match(/(tt|erb)$/)
102
+ end
103
+
104
+ end
105
+
106
+ end
107
+ end
@@ -1,3 +1,3 @@
1
1
  module Dotify
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+ require 'dotify/cli'
3
+
4
+ describe Dotify::CLI do
5
+
6
+ let(:cli) { Dotify::CLI }
7
+ let(:dotify_path) { cli::DOTIFY_PATH }
8
+
9
+ before do
10
+ FileUtils.mkdir_p dotify_path
11
+ end
12
+
13
+ after do
14
+ FileUtils.rm_rf dotify_path
15
+ end
16
+
17
+ describe Dotify::CLI, "#setup" do
18
+ it "it should create the right directory" do
19
+ FileUtils.should_receive(:mkdir_p).with(dotify_path)
20
+ cli.new.setup
21
+ end
22
+ end
23
+
24
+ describe Dotify::CLI, "#dotfile_list" do
25
+ let(:c) { cli.new }
26
+ it "should pull the correct set of files" do
27
+ list = c.dotfile_list
28
+ list.count.should == 0
29
+ end
30
+ end
31
+
32
+ describe Dotify::CLI, "#filename" do
33
+ it "should return only the filename given a path" do
34
+ c = cli.new
35
+ c.filename("/Users/johndoe/filename").should == "filename"
36
+ c.filename("/Users/johndoe/..").should == ".."
37
+ c.filename("/Users/johndoe/.vimrc").should == ".vimrc"
38
+ end
39
+ end
40
+
41
+ describe Dotify::CLI, "#template?" do
42
+ it "should return true if the file ends in tt or erb" do
43
+ c = cli.new
44
+ c.template?("title.tt").should be_true
45
+ c.template?("title.erb").should be_true
46
+ c.template?("title.rb").should_not be_true
47
+ c.template?("title.rb").should_not be_true
48
+ c.template?("#{dotify_path}/title.rb").should_not be_true
49
+ c.template?("#{dotify_path}/tt.rb").should_not be_true
50
+ c.template?("#{dotify_path}/.vimrc.erb").should be_true
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,15 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ $:.unshift File.expand_path("../../lib", __FILE__)
8
+ RSpec.configure do |config|
9
+ config.treat_symbols_as_metadata_keys_with_true_values = true
10
+ config.run_all_when_everything_filtered = true
11
+ config.filter_run :focus
12
+ end
13
+
14
+ ENV['DOTIFY_DIR_NAME'] = '.dotify-test'
15
+ ENV['DOTIFY_PATH'] = '~/.dotify-test'
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.0.1
4
+ version: 0.0.2
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-06-13 00:00:00.000000000 Z
12
+ date: 2012-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -43,21 +43,43 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  description: A CLI Tool for managing your dotfiles and profiles.
47
63
  email:
48
64
  - mbridges.91@gmail.com
49
- executables: []
65
+ executables:
66
+ - dotify
50
67
  extensions: []
51
68
  extra_rdoc_files: []
52
69
  files:
53
70
  - .gitignore
71
+ - .rspec
54
72
  - Gemfile
55
73
  - LICENSE
56
74
  - README.md
57
75
  - Rakefile
76
+ - bin/dotify
58
77
  - dotify.gemspec
59
78
  - lib/dotify.rb
79
+ - lib/dotify/cli.rb
60
80
  - lib/dotify/version.rb
81
+ - spec/dotify/cli_spec.rb
82
+ - spec/spec_helper.rb
61
83
  homepage: https://github.com/mattdbridges/dotify
62
84
  licenses: []
63
85
  post_install_message:
@@ -82,4 +104,6 @@ rubygems_version: 1.8.23
82
104
  signing_key:
83
105
  specification_version: 3
84
106
  summary: A CLI Tool for managing your dotfiles and profiles.
85
- test_files: []
107
+ test_files:
108
+ - spec/dotify/cli_spec.rb
109
+ - spec/spec_helper.rb