Symlink_Creator 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +37 -0
- data/Rakefile +1 -0
- data/bin/SymlinkCreator +3 -0
- data/lib/create_symlink.rb +7 -0
- data/lib/profile.rb +47 -0
- data/lib/version.rb +3 -0
- data/spec/create_symlink_spec.rb +17 -0
- data/spec/features/create_symlinks.feature +12 -0
- data/spec/features/steps/create_symlinks_steps.rb +46 -0
- data/spec/profile_spec.rb +82 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/test_data/duplicate.txt +1 -0
- data/spec/test_data/profile/Untitled.rtf +7 -0
- data/spec/test_data/profile2/duplicate.txt +1 -0
- data/spec/test_data/profile2/not_duplicate.txt +1 -0
- data/spec/test_data/profile3/Untitled.rft +7 -0
- data/symlink_creator.gemspec +19 -0
- metadata +111 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.swp
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
coderay (1.0.9)
|
5
|
+
diff-lcs (1.1.3)
|
6
|
+
gherkin (2.12.0)
|
7
|
+
multi_json (~> 1.3)
|
8
|
+
json (1.7.7)
|
9
|
+
method_source (0.8.1)
|
10
|
+
multi_json (1.7.3)
|
11
|
+
pry (0.9.12.2)
|
12
|
+
coderay (~> 1.0.5)
|
13
|
+
method_source (~> 0.8)
|
14
|
+
slop (~> 3.4)
|
15
|
+
rake (10.3.2)
|
16
|
+
rspec (2.11.0)
|
17
|
+
rspec-core (~> 2.11.0)
|
18
|
+
rspec-expectations (~> 2.11.0)
|
19
|
+
rspec-mocks (~> 2.11.0)
|
20
|
+
rspec-core (2.11.1)
|
21
|
+
rspec-expectations (2.11.3)
|
22
|
+
diff-lcs (~> 1.1.3)
|
23
|
+
rspec-mocks (2.11.3)
|
24
|
+
slop (3.4.4)
|
25
|
+
turnip (1.0.0)
|
26
|
+
gherkin (>= 2.5)
|
27
|
+
rspec (~> 2.0)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
json (~> 1.7.7)
|
34
|
+
pry (~> 0.9.12.2)
|
35
|
+
rake (~> 10.3.2)
|
36
|
+
rspec (~> 2.11.0)
|
37
|
+
turnip (~> 1.0.0)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/SymlinkCreator
ADDED
data/lib/profile.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
class Profile
|
2
|
+
attr_accessor :folder
|
3
|
+
|
4
|
+
def initialize(folder)
|
5
|
+
@folder = folder
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute
|
9
|
+
prepare_folder
|
10
|
+
create_symlinks(@files)
|
11
|
+
end
|
12
|
+
|
13
|
+
def prepare_folder
|
14
|
+
@files = []
|
15
|
+
Dir.foreach(path) do |file|
|
16
|
+
unless file == '.git'
|
17
|
+
remove_old_symlinks(file)
|
18
|
+
remove_existing_files(file)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def remove_old_symlinks(file)
|
24
|
+
if File.symlink?("#{path}/../#{file}")
|
25
|
+
system("rm #{path}/../#{file}")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def remove_existing_files(file)
|
30
|
+
if File.exist?("#{path}/../#{file}")
|
31
|
+
puts "The #{file} already exists"
|
32
|
+
else
|
33
|
+
@files << file
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_symlinks(files)
|
38
|
+
files.each do |file|
|
39
|
+
File.symlink("#{path}/#{file}", "#{path}/../#{file}")
|
40
|
+
puts "symlink created for #{file}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def path
|
45
|
+
File.expand_path("~/#{folder}")
|
46
|
+
end
|
47
|
+
end
|
data/lib/version.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SymlinkCreator do
|
4
|
+
describe '##start' do
|
5
|
+
it 'make a call setup profile command' do
|
6
|
+
Profile.any_instance.should_receive(:execute).once
|
7
|
+
SymlinkCreator.start 'folder'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Profile
|
13
|
+
def initialize(folder)
|
14
|
+
@folder = folder
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Feature: Create Symlinks
|
2
|
+
@create_symlinks
|
3
|
+
Scenario: Symlinks should be created for files in a directory
|
4
|
+
Given there are files in a directory
|
5
|
+
When I run the create symlink command
|
6
|
+
Then I should have symlinks created for each file in the directory
|
7
|
+
|
8
|
+
@create_symlinks
|
9
|
+
Scenario: Should create a symlink for your file even if symlinks already exists
|
10
|
+
Given there is a folder with symlinks already created
|
11
|
+
When I run the create symlink command with folder 3
|
12
|
+
Then the existing symlinks should be removed and created for my directory
|
@@ -0,0 +1,46 @@
|
|
1
|
+
steps_for :create_symlinks do
|
2
|
+
step 'there are files in a directory' do
|
3
|
+
Profile.any_instance.stub(:path).and_return('spec/test_data/profile')
|
4
|
+
end
|
5
|
+
|
6
|
+
step 'there is a folder with symlinks already created' do
|
7
|
+
path = "spec/test_data/profile3"
|
8
|
+
Profile.any_instance.stub(:path).and_return('spec/test_data/profile3')
|
9
|
+
|
10
|
+
file = 'Untitled.rft'
|
11
|
+
File.symlink("#{path}/#{file}", "#{path}/../#{file}")
|
12
|
+
end
|
13
|
+
|
14
|
+
step 'I run the create symlink command' do
|
15
|
+
SymlinkCreator.start 'test_data/profile'
|
16
|
+
end
|
17
|
+
|
18
|
+
step 'I run the create symlink command with folder 3' do
|
19
|
+
SymlinkCreator.start 'test_data/profile3'
|
20
|
+
end
|
21
|
+
|
22
|
+
step 'I should have symlinks created for each file in the directory' do
|
23
|
+
Dir.foreach('spec/test_data/profile') do |file|
|
24
|
+
unless file == '.' || '..'
|
25
|
+
File.symlink?(file).should be_true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
##removes synlink if exists
|
29
|
+
Dir.foreach('spec/test_data/profile') do |file|
|
30
|
+
if file != '.' && file != '..'
|
31
|
+
system("rm 'spec/test_data/#{file}'")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
step 'the existing symlinks should be removed and created for my directory' do
|
38
|
+
File.readlink('spec/test_data/Untitled.rft').should == 'spec/test_data/profile3/Untitled.rft'
|
39
|
+
##removes synlink if exists
|
40
|
+
Dir.foreach('spec/test_data/profile3') do |file|
|
41
|
+
if file != '.' && file != '..'
|
42
|
+
system("rm 'spec/test_data/#{file}'")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require File.expand_path("../../lib/profile", __FILE__)
|
3
|
+
|
4
|
+
describe Profile do
|
5
|
+
describe '#execute' do
|
6
|
+
let(:profile) { Profile.new 'some_folder' }
|
7
|
+
it 'should call prepare_folder and then create_symlinks' do
|
8
|
+
Profile.any_instance.should_receive(:prepare_folder)
|
9
|
+
Profile.any_instance.should_receive(:create_symlinks)
|
10
|
+
profile.execute
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#prepare_folder' do
|
15
|
+
let(:profile) { Profile.new 'spec/test_data/profile2' }
|
16
|
+
before :each do
|
17
|
+
profile.stub(:path).and_return('spec/test_data/profile2')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'makes a call remove old symlinks for each file in directory' do
|
21
|
+
profile.stub(:remove_existing_files).and_return(true)
|
22
|
+
|
23
|
+
Profile.any_instance.should_receive(:remove_old_symlinks).exactly(4).times
|
24
|
+
profile.prepare_folder
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'makes a call to remove existing files for each file in directory' do
|
28
|
+
profile.stub(:remove_old_symlinks).and_return(true)
|
29
|
+
|
30
|
+
Profile.any_instance.should_receive(:remove_existing_files).exactly(4).times
|
31
|
+
profile.prepare_folder
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#remove_old_symlinks" do
|
36
|
+
let(:profile) { Profile.new 'some_folder' }
|
37
|
+
it 'removes symlinks for old files' do
|
38
|
+
File.symlink("spec/test_data/profile2/not_duplicate.txt", "spec/test_data/not_duplicate.txt")
|
39
|
+
profile.stub(:path).and_return('spec/test_data/profile2')
|
40
|
+
profile.remove_old_symlinks("not_duplicate.txt")
|
41
|
+
|
42
|
+
File.symlink?("spec/test_data/not_duplicate.txt").should == false
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#remove_existing_files' do
|
48
|
+
let(:profile) { Profile.new 'some_folder' }
|
49
|
+
|
50
|
+
it "return a file if it does not exist" do
|
51
|
+
profile.remove_existing_files('file.txt').should == ['file.txt']
|
52
|
+
end
|
53
|
+
|
54
|
+
it "not return the file if it does exist" do
|
55
|
+
profile.remove_existing_files('duplicate.txt').should_not == ['file.txt']
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#create_symlinks' do
|
60
|
+
let(:profile) { Profile.new 'spec/test_data/profile' }
|
61
|
+
|
62
|
+
it 'should create symlinks for files in a directory' do
|
63
|
+
files = []
|
64
|
+
|
65
|
+
Dir.foreach('spec/test_data/profile')do |file|
|
66
|
+
unless file == '.' || '..'
|
67
|
+
files << file
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
profile.create_symlinks(files)
|
72
|
+
files.each do |file|
|
73
|
+
File.symlink?("spec/test_data/#{file}").should == true
|
74
|
+
end
|
75
|
+
|
76
|
+
## cleanup
|
77
|
+
files.each do |file|
|
78
|
+
system("rm 'spec/test_data/#{file}'")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
This file is a duplicate
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{\rtf1\ansi\ansicpg1252\cocoartf1138\cocoasubrtf510
|
2
|
+
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
|
3
|
+
{\colortbl;\red255\green255\blue255;}
|
4
|
+
\margl1440\margr1440\vieww10800\viewh8400\viewkind0
|
5
|
+
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
|
6
|
+
|
7
|
+
\f0\fs24 \cf0 hi}
|
@@ -0,0 +1 @@
|
|
1
|
+
This file is a duplicate
|
@@ -0,0 +1 @@
|
|
1
|
+
This file is not
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{\rtf1\ansi\ansicpg1252\cocoartf1138\cocoasubrtf510
|
2
|
+
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
|
3
|
+
{\colortbl;\red255\green255\blue255;}
|
4
|
+
\margl1440\margr1440\vieww10800\viewh8400\viewkind0
|
5
|
+
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
|
6
|
+
|
7
|
+
\f0\fs24 \cf0 hi}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "#{lib}/version.rb"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = %q{Symlink_Creator}
|
7
|
+
s.version = SymlinkCreator::VERSION
|
8
|
+
s.author = "Andy Smith"
|
9
|
+
s.date = %q{2014-07-29}
|
10
|
+
s.summary = %q{Creates symlink for you from a specified folder}
|
11
|
+
s.files = `git ls-files`.split("\n")-%w(spec/Untitled.rft)
|
12
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") -%w(spec/Untitled.rft)
|
13
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
s.license = "MIT"
|
16
|
+
|
17
|
+
s.add_development_dependency "bundler", "~> 1.5"
|
18
|
+
s.add_development_dependency "rake"
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Symlink_Creator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andy Smith
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-07-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.5'
|
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: '1.5'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
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: '0'
|
46
|
+
description:
|
47
|
+
email:
|
48
|
+
executables:
|
49
|
+
- SymlinkCreator
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- .rspec
|
55
|
+
- Gemfile
|
56
|
+
- Gemfile.lock
|
57
|
+
- Rakefile
|
58
|
+
- bin/SymlinkCreator
|
59
|
+
- lib/create_symlink.rb
|
60
|
+
- lib/profile.rb
|
61
|
+
- lib/version.rb
|
62
|
+
- spec/create_symlink_spec.rb
|
63
|
+
- spec/features/create_symlinks.feature
|
64
|
+
- spec/features/steps/create_symlinks_steps.rb
|
65
|
+
- spec/profile_spec.rb
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
- spec/test_data/duplicate.txt
|
68
|
+
- spec/test_data/profile/Untitled.rtf
|
69
|
+
- spec/test_data/profile2/duplicate.txt
|
70
|
+
- spec/test_data/profile2/not_duplicate.txt
|
71
|
+
- spec/test_data/profile3/Untitled.rft
|
72
|
+
- symlink_creator.gemspec
|
73
|
+
homepage:
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
hash: 3599463298128991304
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.8.23
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: Creates symlink for you from a specified folder
|
101
|
+
test_files:
|
102
|
+
- spec/create_symlink_spec.rb
|
103
|
+
- spec/features/create_symlinks.feature
|
104
|
+
- spec/features/steps/create_symlinks_steps.rb
|
105
|
+
- spec/profile_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/test_data/duplicate.txt
|
108
|
+
- spec/test_data/profile/Untitled.rtf
|
109
|
+
- spec/test_data/profile2/duplicate.txt
|
110
|
+
- spec/test_data/profile2/not_duplicate.txt
|
111
|
+
- spec/test_data/profile3/Untitled.rft
|