homer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +31 -0
- data/LICENSE.txt +20 -0
- data/README.md +35 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/bin/homer +69 -0
- data/homer.gemspec +70 -0
- data/lib/homer/file_layer.rb +73 -0
- data/lib/homer/github_layer.rb +27 -0
- data/lib/homer/symlink.rb +30 -0
- data/lib/homer.rb +28 -0
- data/lib/symlink.rb +0 -0
- data/spec/file_layer_spec.rb +43 -0
- data/spec/github_layer_spec.rb +47 -0
- data/spec/homer_spec.rb +61 -0
- data/spec/spec_helper.rb +16 -0
- metadata +136 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler"
|
12
|
+
gem "jeweler", "~> 1.8.4"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.8.4)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rdoc
|
11
|
+
json (1.7.5)
|
12
|
+
rake (0.9.2.2)
|
13
|
+
rdoc (3.12)
|
14
|
+
json (~> 1.4)
|
15
|
+
rspec (2.11.0)
|
16
|
+
rspec-core (~> 2.11.0)
|
17
|
+
rspec-expectations (~> 2.11.0)
|
18
|
+
rspec-mocks (~> 2.11.0)
|
19
|
+
rspec-core (2.11.1)
|
20
|
+
rspec-expectations (2.11.3)
|
21
|
+
diff-lcs (~> 1.1.3)
|
22
|
+
rspec-mocks (2.11.2)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
bundler
|
29
|
+
jeweler (~> 1.8.4)
|
30
|
+
rdoc (~> 3.12)
|
31
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Emil Soman
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Homer
|
2
|
+
|
3
|
+
|
4
|
+
Homer makes tracking your Unix dotfiles easay peasay
|
5
|
+
|
6
|
+
-Currently under development and not yet available -
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
gem install homer
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
- Initialize homer :
|
14
|
+
|
15
|
+
homer init
|
16
|
+
- Start tracking dotfiles :
|
17
|
+
|
18
|
+
homer add ~/.vimrc
|
19
|
+
- List tracked files :
|
20
|
+
|
21
|
+
homer list
|
22
|
+
- Push tracked files to GitHub
|
23
|
+
|
24
|
+
homer push
|
25
|
+
|
26
|
+
A few days later ..
|
27
|
+
|
28
|
+
Need to pair program at co-worker's hostile box .
|
29
|
+
|
30
|
+
- To turn on ninja mode at hostile box:
|
31
|
+
|
32
|
+
homer hi <github login>
|
33
|
+
- When friend complains after your display of awesomeness
|
34
|
+
|
35
|
+
homer bye
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= homer
|
2
|
+
|
3
|
+
Homer makes tracking your Unix dotfiles easay peasay
|
4
|
+
|
5
|
+
== Contributing to homer
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Emil Soman. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "homer"
|
18
|
+
gem.homepage = "http://github.com/emilsoman/homer"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Homer makes tracking your Unix dotfiles easay peasay - UNDER DEVELOPMENT}
|
21
|
+
gem.description = %Q{Homer makes tracking your Unix dotfiles easay peasay - UNDER DEVELOPMENT}
|
22
|
+
gem.email = "emil.soman@gmail.com"
|
23
|
+
gem.authors = ["Emil Soman"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "homer #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/homer
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'homer'
|
5
|
+
|
6
|
+
class HomerRunner < Thor
|
7
|
+
|
8
|
+
default_task :help
|
9
|
+
|
10
|
+
desc "wipe", "Removes ~/.homer folder"
|
11
|
+
def wipe
|
12
|
+
Homer.wipe
|
13
|
+
rescue Exception => e
|
14
|
+
puts "Error: #{e.message}"
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "init", "Initializes homer. Creates ~/.homer folder"
|
18
|
+
def init
|
19
|
+
Homer.init
|
20
|
+
rescue Exception => e
|
21
|
+
puts "Error: #{e.message}"
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "list", "Lists your tracked dotfiles"
|
25
|
+
def list
|
26
|
+
puts Homer.list
|
27
|
+
rescue Exception => e
|
28
|
+
puts "Error: #{e.message}"
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "add DOTFILE", "Start tracking a file"
|
32
|
+
def add(file)
|
33
|
+
Homer.add(file)
|
34
|
+
rescue Exception => e
|
35
|
+
puts "Error: #{e.message}"
|
36
|
+
puts "Did you forget to run 'homer init' after you installed Homer gem ?"
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "push", "Pushes your dotfiles to GitHub"
|
40
|
+
def push
|
41
|
+
puts "This should push the dotfiles folder to github"
|
42
|
+
rescue Exception => e
|
43
|
+
puts "Error: #{e.message}"
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "hi", "Magically brings your dotfiles from GitHub so you can feel at home"
|
47
|
+
def hi
|
48
|
+
puts "This should take a backup of existing dotfiles, ask your github username and password and pull your dotfiles"
|
49
|
+
rescue Exception => e
|
50
|
+
puts "Error: #{e.message}"
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "bye", "Self destructs leaving no trace behind"
|
54
|
+
def bye
|
55
|
+
puts "This should restore the dotfiles backup and delete the .homer folder"
|
56
|
+
rescue Exception => e
|
57
|
+
puts "Error: #{e.message}"
|
58
|
+
end
|
59
|
+
|
60
|
+
desc "restore", "Move back original files and remove symlinks"
|
61
|
+
def restore
|
62
|
+
puts "This should move back the original dotfiles and remove all symlinks"
|
63
|
+
rescue Exception => e
|
64
|
+
puts "Error: #{e.message}"
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
HomerRunner.start
|
data/homer.gemspec
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "homer"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Emil Soman"]
|
12
|
+
s.date = "2012-10-01"
|
13
|
+
s.description = "Homer makes tracking your Unix dotfiles easay peasay - UNDER DEVELOPMENT"
|
14
|
+
s.email = "emil.soman@gmail.com"
|
15
|
+
s.executables = ["homer"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.md",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".rspec",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.md",
|
28
|
+
"README.rdoc",
|
29
|
+
"Rakefile",
|
30
|
+
"VERSION",
|
31
|
+
"bin/homer",
|
32
|
+
"homer.gemspec",
|
33
|
+
"lib/homer.rb",
|
34
|
+
"lib/homer/file_layer.rb",
|
35
|
+
"lib/homer/github_layer.rb",
|
36
|
+
"lib/homer/symlink.rb",
|
37
|
+
"lib/symlink.rb",
|
38
|
+
"spec/file_layer_spec.rb",
|
39
|
+
"spec/github_layer_spec.rb",
|
40
|
+
"spec/homer_spec.rb",
|
41
|
+
"spec/spec_helper.rb"
|
42
|
+
]
|
43
|
+
s.homepage = "http://github.com/emilsoman/homer"
|
44
|
+
s.licenses = ["MIT"]
|
45
|
+
s.require_paths = ["lib"]
|
46
|
+
s.rubygems_version = "1.8.24"
|
47
|
+
s.summary = "Homer makes tracking your Unix dotfiles easay peasay - UNDER DEVELOPMENT"
|
48
|
+
|
49
|
+
if s.respond_to? :specification_version then
|
50
|
+
s.specification_version = 3
|
51
|
+
|
52
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
55
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
59
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
60
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
61
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
65
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
66
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
67
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'homer/symlink'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
class FileLayer
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def save_authorization_token(token)
|
9
|
+
f = File.open(token_path, "a")
|
10
|
+
f.puts token
|
11
|
+
f.close
|
12
|
+
rescue Exception => e
|
13
|
+
raise "GitHub token could not be saved : Error : #{e.message}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def prepare_homer_folder
|
17
|
+
Dir.mkdir(File.join(Dir.home, ".homer")) unless Dir.exists?(File.join(Dir.home, ".homer"))
|
18
|
+
Dir.mkdir(File.join(Dir.home, ".homer", "dotfiles")) unless Dir.exists?(File.join(Dir.home, ".homer", "dotfiles"))
|
19
|
+
File.new(dotfiles_path , "w") unless File.exists?(dotfiles_path)
|
20
|
+
rescue Exception => e
|
21
|
+
raise "~/.homer cannot be created : #{e.message}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete_homer_folder
|
25
|
+
FileUtils.rm_rf(File.join(Dir.home, ".homer"))
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_filename_to_dotfiles(dotfile)
|
29
|
+
dotfile = File.expand_path(dotfile)
|
30
|
+
f = File.open(dotfiles_path, "a")
|
31
|
+
raise "#{dotfile} does not exist." unless File.exists?(dotfile)
|
32
|
+
f.puts dotfile
|
33
|
+
f.close
|
34
|
+
end
|
35
|
+
|
36
|
+
def read_symlink_file
|
37
|
+
return {} if !File.exists?(dotfiles_path) or File.zero?(dotfiles_path)
|
38
|
+
YAML.load_file(dotfiles_path)
|
39
|
+
end
|
40
|
+
|
41
|
+
def save_symlink_file(symlinks)
|
42
|
+
File.open(dotfiles_path,"w") do |out|
|
43
|
+
YAML.dump(symlinks,out)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_symlink(filename,file_path)
|
48
|
+
FileUtils.mv(file_path, File.join(dotfiles_directory_path, filename))
|
49
|
+
File.symlink(File.join(dotfiles_directory_path, filename), file_path)
|
50
|
+
end
|
51
|
+
|
52
|
+
def dotfiles_directory_path
|
53
|
+
File.join(Dir.home, ".homer", "dotfiles", "/")
|
54
|
+
end
|
55
|
+
|
56
|
+
def dotfiles_path
|
57
|
+
return File.join(Dir.home, ".homer", "dotfiles", "dotfiles_list")
|
58
|
+
end
|
59
|
+
|
60
|
+
def root_path
|
61
|
+
return File.join(Dir.home, ".homer")
|
62
|
+
end
|
63
|
+
|
64
|
+
def token_path
|
65
|
+
File.join(root_path, "token")
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_generic_home_relative_path(filepath)
|
69
|
+
filepath.gsub(/\/home\/[^\/]*\//, "~/")
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'github_api'
|
2
|
+
require 'homer/file_layer'
|
3
|
+
Github::Authorizations::VALID_AUTH_PARAM_NAMES = Github::Authorizations::VALID_AUTH_PARAM_NAMES + ["note"]
|
4
|
+
|
5
|
+
class GitHubLayer
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def login(login, password)
|
9
|
+
github = Github.new(login: login, password: password)
|
10
|
+
authorization = github.oauth.create(scopes: ['public_repo'], note: 'Homer')
|
11
|
+
FileLayer.save_authorization_token(authorization.token)
|
12
|
+
rescue Github::Error::Unauthorized
|
13
|
+
raise "Invalid GitHub Login/Password"
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_repo_if_repo_does_not_exist(repo_name)
|
17
|
+
token = FileLayer.read_authorization_token
|
18
|
+
github = Github.new(oauth_token: token)
|
19
|
+
begin
|
20
|
+
github.repos.get(github.login, repo_name)
|
21
|
+
rescue Github::Error::NotFound
|
22
|
+
github.repos.create(name: repo_name)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class SymLink
|
2
|
+
|
3
|
+
def self.filenames
|
4
|
+
symlinks = FileLayer.read_symlink_file
|
5
|
+
symlinks.keys
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.add(dotfile)
|
9
|
+
dotfile = File.expand_path(dotfile)
|
10
|
+
raise "#{dotfile} does not exist." unless File.exists?(dotfile)
|
11
|
+
filename = File.basename(dotfile)
|
12
|
+
filename_to_store = get_unused_filename(filename, filenames)
|
13
|
+
symlinks = FileLayer.read_symlink_file
|
14
|
+
symlinks[filename_to_store] = FileLayer.get_generic_home_relative_path(dotfile)
|
15
|
+
FileLayer.save_symlink_file(symlinks)
|
16
|
+
FileLayer.create_symlink(filename_to_store,dotfile)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def self.get_unused_filename(filename, existing_filenames)
|
21
|
+
filename_to_store = filename
|
22
|
+
count = 1
|
23
|
+
until !existing_filenames.include?(filename_to_store)
|
24
|
+
filename_to_store = filename + "_" + count.to_s
|
25
|
+
count += 1
|
26
|
+
end
|
27
|
+
return filename_to_store
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/homer.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'homer/file_layer'
|
2
|
+
require 'homer/symlink'
|
3
|
+
|
4
|
+
class Homer
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def init
|
9
|
+
FileLayer.prepare_homer_folder
|
10
|
+
end
|
11
|
+
|
12
|
+
def wipe
|
13
|
+
FileLayer.delete_homer_folder
|
14
|
+
end
|
15
|
+
|
16
|
+
def add(dotfile)
|
17
|
+
FileLayer.prepare_homer_folder
|
18
|
+
SymLink.add(dotfile)
|
19
|
+
end
|
20
|
+
|
21
|
+
def list
|
22
|
+
SymLink.filenames
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
data/lib/symlink.rb
ADDED
File without changes
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FileLayer do
|
4
|
+
describe ".get_generic_home_relative_path" do
|
5
|
+
it "should replace /home/xyz/ with ~/" do
|
6
|
+
file_path = "/home/emil/somefolder/subfolder/.dotfile"
|
7
|
+
FileLayer.get_generic_home_relative_path(file_path).should == "~/somefolder/subfolder/.dotfile"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ".root_path" do
|
12
|
+
it "should return the root folder for homer to store meta info" do
|
13
|
+
FileLayer.root_path.should == File.join(Dir.home, ".homer")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".dotfiles_path" do
|
18
|
+
it "should return the path to dotfiles_list" do
|
19
|
+
FileLayer.dotfiles_path.should == File.join(Dir.home, ".homer", "dotfiles", "dotfiles_list")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe ".token_path" do
|
24
|
+
it "should return the path to file where GitHub token is saved" do
|
25
|
+
FileLayer.token_path.should == File.join(Dir.home, ".homer", "token")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe ".dotfiles_directory_path" do
|
30
|
+
it "should return the path to folder which will be pushed to GitHub" do
|
31
|
+
FileLayer.dotfiles_directory_path.should == File.join(Dir.home, ".homer", "dotfiles/")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".save_authorization_token" do
|
36
|
+
it "should store token into token file" do
|
37
|
+
Homer.init
|
38
|
+
FileLayer.save_authorization_token("abc")
|
39
|
+
Homer.wipe
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'homer/github_layer'
|
3
|
+
|
4
|
+
describe GitHubLayer do
|
5
|
+
|
6
|
+
describe "create_token" do
|
7
|
+
context "invalid credentials" do
|
8
|
+
it "should raise exception" do
|
9
|
+
github = double('GitHub')
|
10
|
+
Github.should_receive(:new).with(login: "login",password: "password").and_return(github)
|
11
|
+
github.should_receive(:oauth).and_raise(Github::Error::Unauthorized.new({}))
|
12
|
+
expect { GitHubLayer.login("login","password") }.to raise_error "Invalid GitHub Login/Password"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
context "valid credentials" do
|
16
|
+
it "should save the authorization token" do
|
17
|
+
github = double('GitHub').as_null_object
|
18
|
+
Github.should_receive(:new).with(login: "login", password: "password").and_return(github)
|
19
|
+
github.stub_chain(:oauth, :create).and_return Hashie::Mash.new({"token" => "received_token" })
|
20
|
+
FileLayer.should_receive(:save_authorization_token).with("received_token")
|
21
|
+
GitHubLayer.login("login","password")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "create_repo" do
|
27
|
+
it "should create a repository"
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "initialization" do
|
31
|
+
it "should log in to github account with login and password"
|
32
|
+
describe "handling dotfiles repo" do
|
33
|
+
context "when dotfiles repo already exists" do
|
34
|
+
context "when homer folder does not exist inside the dotfiles repo" do
|
35
|
+
it "should create the directory"
|
36
|
+
end
|
37
|
+
context "when homer folder does not exist inside the dotfiles repo" do
|
38
|
+
it "should ask the user what to do"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
context "when dotfiles repo does not exist" do
|
42
|
+
it "should create the repo"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/spec/homer_spec.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Homer do
|
4
|
+
describe "initialize" do
|
5
|
+
before (:each) do
|
6
|
+
Homer.wipe
|
7
|
+
Homer.init
|
8
|
+
end
|
9
|
+
it "should create a .homer folder in home directory" do
|
10
|
+
Dir.exists?(File.join(Dir.home, '.homer')).should be_true
|
11
|
+
end
|
12
|
+
it "should create a .homer folder in home directory" do
|
13
|
+
Dir.exists?(File.join(Dir.home,'.homer/dotfiles')).should be_true
|
14
|
+
end
|
15
|
+
it "should create an empty dotfiles file in ~/.homer" do
|
16
|
+
File.zero?(File.join(Dir.home,'.homer/dotfiles/dotfiles_list')).should be_true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "adding a dotfile" do
|
21
|
+
context "when dotfile doesnt exist" do
|
22
|
+
it "should raise error when dotfile does not exist" do
|
23
|
+
expect do
|
24
|
+
Homer.add('~/.file_that_does_not_exist')
|
25
|
+
end.to raise_error("#{ENV['HOME']}/.file_that_does_not_exist does not exist.")
|
26
|
+
#File.read(Homer.dotfiles_path).should include(File.join(Dir.home, ".file_that_does_not_exist"))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
context "when dotfile exists" do
|
30
|
+
it "should raise error when dotfile does not exist" do
|
31
|
+
File.new("/tmp/.file_that_exists", "w")
|
32
|
+
File.new("/tmp/.another_file_that_exists", "w")
|
33
|
+
expect do
|
34
|
+
Homer.add('/tmp/.file_that_exists')
|
35
|
+
Homer.add('/tmp/.another_file_that_exists')
|
36
|
+
end.not_to raise_error
|
37
|
+
YAML.load_file(FileLayer.dotfiles_path).should == {".file_that_exists" => '/tmp/.file_that_exists', ".another_file_that_exists" => '/tmp/.another_file_that_exists'}
|
38
|
+
File.delete(File.join(Dir.home, ".file_that_exists"))
|
39
|
+
File.delete(File.join(Dir.home, ".another_file_that_exists"))
|
40
|
+
Homer.wipe
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe ".list" do
|
46
|
+
it "should list the contents of dotfiles" do
|
47
|
+
Homer.wipe
|
48
|
+
Homer.init
|
49
|
+
File.new(File.join(Dir.home, ".file_that_exists"), "w")
|
50
|
+
File.new(File.join(Dir.home, ".another_file_that_exists"), "w")
|
51
|
+
Homer.add(File.join(Dir.home, ".file_that_exists"))
|
52
|
+
Homer.add(File.join(Dir.home, ".another_file_that_exists"))
|
53
|
+
Homer.list.should include(".file_that_exists")
|
54
|
+
Homer.list.should include(".another_file_that_exists")
|
55
|
+
File.delete(File.join(Dir.home, ".file_that_exists"))
|
56
|
+
File.delete(File.join(Dir.home, ".another_file_that_exists"))
|
57
|
+
Homer.wipe
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'homer'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.mock_with :rspec
|
12
|
+
config.before(:each) do
|
13
|
+
Dir.stub(:home).and_return('/tmp')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: homer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Emil Soman
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.12'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.12'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
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'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.4
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.8.4
|
78
|
+
description: Homer makes tracking your Unix dotfiles easay peasay - UNDER DEVELOPMENT
|
79
|
+
email: emil.soman@gmail.com
|
80
|
+
executables:
|
81
|
+
- homer
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files:
|
84
|
+
- LICENSE.txt
|
85
|
+
- README.md
|
86
|
+
- README.rdoc
|
87
|
+
files:
|
88
|
+
- .document
|
89
|
+
- .rspec
|
90
|
+
- Gemfile
|
91
|
+
- Gemfile.lock
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- README.rdoc
|
95
|
+
- Rakefile
|
96
|
+
- VERSION
|
97
|
+
- bin/homer
|
98
|
+
- homer.gemspec
|
99
|
+
- lib/homer.rb
|
100
|
+
- lib/homer/file_layer.rb
|
101
|
+
- lib/homer/github_layer.rb
|
102
|
+
- lib/homer/symlink.rb
|
103
|
+
- lib/symlink.rb
|
104
|
+
- spec/file_layer_spec.rb
|
105
|
+
- spec/github_layer_spec.rb
|
106
|
+
- spec/homer_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
homepage: http://github.com/emilsoman/homer
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
hash: 980253459
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ! '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 1.8.24
|
133
|
+
signing_key:
|
134
|
+
specification_version: 3
|
135
|
+
summary: Homer makes tracking your Unix dotfiles easay peasay - UNDER DEVELOPMENT
|
136
|
+
test_files: []
|