polka 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +30 -0
- data/bin/polka +0 -1
- data/lib/polka/bootstrapper.rb +7 -3
- data/lib/polka/dotfile_group.rb +1 -1
- data/lib/polka/operations/parsed_copying.rb +6 -5
- data/lib/polka/version.rb +1 -1
- data/lib/polka.rb +8 -0
- data/spec/polka/bootstrapper_spec.rb +8 -0
- data/spec/polka/operations/parsed_copying_spec.rb +22 -2
- metadata +9 -8
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Polka
|
2
|
+
Polka sets up your dotfiles
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
gem install polka
|
6
|
+
|
7
|
+
In your dotfile directory create a file called `Dotfile`. My Dotfile looks like this:
|
8
|
+
|
9
|
+
symlink ".gemrc", ".vimrc", ".zshrc", ".zsh_custom", ".vim"
|
10
|
+
symlink ".gitignore_global", as: ".gitignore"
|
11
|
+
copy ".gitconfig.erb"
|
12
|
+
|
13
|
+
Once you are done, run `polka setup`. Existing files will be moved to a backup dir.
|
14
|
+
|
15
|
+
You can avoid name collisions in your .dotfile directory by using the `:as` option.
|
16
|
+
|
17
|
+
`.erb`-files are parsed before they are copied: Create a `personal.yml` where you list your personal information that you may not want to check into your git repo (e.g. API tokens, name, email etc.):
|
18
|
+
|
19
|
+
.gitconfig:
|
20
|
+
name: Peter Venkman
|
21
|
+
email: peter@ghostbusters.test
|
22
|
+
|
23
|
+
In `.gitconfig.erb`:
|
24
|
+
|
25
|
+
[user]
|
26
|
+
name = <%= personal['name'] %>
|
27
|
+
email = <%= personal['email'] %>
|
28
|
+
|
29
|
+
`personal.yml` should be added to your `.gitignore`, ldo.
|
30
|
+
|
data/bin/polka
CHANGED
data/lib/polka/bootstrapper.rb
CHANGED
@@ -8,9 +8,9 @@ module Polka
|
|
8
8
|
symlinking = lambda { |dest, src| FileUtils.ln_s(dest, src) }
|
9
9
|
copying = lambda { |dest, src| FileUtils.cp(dest, src) }
|
10
10
|
|
11
|
-
@symlink = DotfileGroup.new(symlinking, " Symlinking files"
|
12
|
-
@copy = DotfileGroup.new(copying, " Copying files"
|
13
|
-
@parsed_copy = DotfileGroup.new(Operations::ParsedCopying, " Parsing and copying files"
|
11
|
+
@symlink = DotfileGroup.new(symlinking, " Symlinking files")
|
12
|
+
@copy = DotfileGroup.new(copying, " Copying files")
|
13
|
+
@parsed_copy = DotfileGroup.new(Operations::ParsedCopying, " Parsing and copying files")
|
14
14
|
@inclusive_groups = [@symlink, @copy, @parsed_copy]
|
15
15
|
@exclude = DotfileGroup.new
|
16
16
|
exclude("Dotfile")
|
@@ -59,6 +59,10 @@ module Polka
|
|
59
59
|
Polka.log "\nSetup completed. Enjoy!\n".green
|
60
60
|
end
|
61
61
|
|
62
|
+
def configure(config_hash)
|
63
|
+
Polka.config.merge!(config_hash)
|
64
|
+
end
|
65
|
+
|
62
66
|
private
|
63
67
|
def add_files_to_group(files, group)
|
64
68
|
dotfiles = files.map { |fn| create_dotfile(fn) }
|
data/lib/polka/dotfile_group.rb
CHANGED
@@ -29,18 +29,19 @@ module Polka
|
|
29
29
|
@dest.gsub(/\.erb$/, "")
|
30
30
|
end
|
31
31
|
|
32
|
+
def context
|
33
|
+
YAML.load_file(yaml_file)[context_name]
|
34
|
+
end
|
35
|
+
|
32
36
|
def yaml_file
|
33
|
-
File.join(File.dirname(@file),
|
37
|
+
filename = Polka.config[:personal_file] || File.join(File.dirname(@file), "personal.yml")
|
38
|
+
File.expand_path(filename)
|
34
39
|
end
|
35
40
|
|
36
41
|
def context_name
|
37
42
|
File.basename(@file, ".erb")
|
38
43
|
end
|
39
44
|
|
40
|
-
def context
|
41
|
-
YAML.load_file(yaml_file)[context_name]
|
42
|
-
end
|
43
|
-
|
44
45
|
def erb
|
45
46
|
ERB.new(File.open(@file) { |f| f.read })
|
46
47
|
end
|
data/lib/polka/version.rb
CHANGED
data/lib/polka.rb
CHANGED
@@ -11,6 +11,14 @@ require_relative "polka/dotfile_group"
|
|
11
11
|
require_relative "polka/operations/parsed_copying"
|
12
12
|
|
13
13
|
module Polka
|
14
|
+
def self.config
|
15
|
+
@config ||= {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.config=(hash)
|
19
|
+
@config = hash
|
20
|
+
end
|
21
|
+
|
14
22
|
def self.log(msg)
|
15
23
|
puts msg
|
16
24
|
end
|
@@ -34,6 +34,14 @@ describe Polka::Bootstrapper do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
describe "#configure" do
|
38
|
+
it "merges the given hash into the config-hash" do
|
39
|
+
config_hash = double(merge!: true)
|
40
|
+
Polka.should_receive(:config).and_return(config_hash)
|
41
|
+
bs.configure personal_file: "~/Dripbox/private.yml"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
37
45
|
describe "#symlink, #exclude, #copy" do
|
38
46
|
describe "addings files without options" do
|
39
47
|
let(:hello_dotfile) { double(:hello_dotfile) }
|
@@ -3,9 +3,29 @@ require "spec_helper"
|
|
3
3
|
describe Polka::Operations::ParsedCopying, :integrated_with_files do
|
4
4
|
set_up_testdirs
|
5
5
|
|
6
|
-
|
6
|
+
before do
|
7
7
|
File.open(File.join(dotfile_dir, "blah.erb"), "w") { |f| f.write("hello <%= personal['name'] %>") }
|
8
|
-
|
8
|
+
end
|
9
|
+
|
10
|
+
def write_personal_file(filename)
|
11
|
+
File.open(filename, "w") { |f| f.write("blah:\n name: ray stanz") }
|
12
|
+
end
|
13
|
+
|
14
|
+
it "parses the erb file and copys the result without the extension" do
|
15
|
+
personal_file = File.join(dotfile_dir, "personal.yml")
|
16
|
+
write_personal_file(personal_file)
|
17
|
+
|
18
|
+
Polka::Operations::ParsedCopying.call(File.join(dotfile_dir, "blah.erb"), File.join(home_dir, "foo.erb"))
|
19
|
+
File.open(File.join(home_dir, "foo")) { |f| f.read }.should == "hello ray stanz"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "uses the personal.yml provided in the config" do
|
23
|
+
another_dir = File.join(dotfile_dir, "another_dir")
|
24
|
+
personal_file = File.join(another_dir, "polka_personal.yml")
|
25
|
+
FileUtils.mkdir(another_dir)
|
26
|
+
write_personal_file(personal_file)
|
27
|
+
|
28
|
+
Polka.stub(:config) { { personal_file: another_dir + "/polka_personal.yml" } }
|
9
29
|
|
10
30
|
Polka::Operations::ParsedCopying.call(File.join(dotfile_dir, "blah.erb"), File.join(home_dir, "foo.erb"))
|
11
31
|
File.open(File.join(home_dir, "foo")) { |f| f.read }.should == "hello ray stanz"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
16
|
-
requirement: &
|
16
|
+
requirement: &70306305111260 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.16.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70306305111260
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: colorize
|
27
|
-
requirement: &
|
27
|
+
requirement: &70306305110480 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - =
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.5.8
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70306305110480
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70306305109660 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '2.11'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70306305109660
|
47
47
|
description: Easy Dotfile Management
|
48
48
|
email:
|
49
49
|
- michi.huber@gmail.com
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- Gemfile
|
57
57
|
- Gemfile.lock
|
58
58
|
- LICENSE
|
59
|
+
- README.md
|
59
60
|
- bin/polka
|
60
61
|
- lib/polka.rb
|
61
62
|
- lib/polka/bootstrapper.rb
|