linknew 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: be28519a2e96cd2c9696e5ddb12f5e3d0f27f0a0
4
+ data.tar.gz: 92802cacc5f7b0f63175eb80593fd10a40d405ff
5
+ SHA512:
6
+ metadata.gz: d9d57838d3192edb70810e6bce3a5fd6943c9f2754f6000d02aae01d0d18c1fcbe7937bb8518cc92a557e640f48b4b68afab78c0b46ce374fd38ec6fc77d7834
7
+ data.tar.gz: 308e6f7dc06ed89602fbea7e62563e9e666401f97a3b9aa76d8f9067bd339db5d0374ea39a2e2f85eb851bcd42fdf87bbcfdedf696b01427b1de147b23c17ce8
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ 2.1.2
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in linknew.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Simon Kohlmeyer
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ # Linknew
2
+
3
+ Linknew creates links to all files in another directory once. You can use it to keep track of which files in a shared
4
+ directory you already looked at.
5
+
6
+ ## Installation
7
+
8
+ $ gem install linknew
9
+
10
+ ## Usage
11
+
12
+ 1. echo "/path/to/target/folder" >> .linknew
13
+ 2. `linknew`
14
+
15
+ ## Contributing
16
+
17
+ 1. Fork it ( https://github.com/[my-github-username]/linknew/fork )
18
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
19
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
20
+ 4. Push to the branch (`git push origin my-new-feature`)
21
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ require 'linknew'
3
+
4
+ CONFIG_FILE = ".linknew"
5
+ HELP_MESSAGE = <<HERE
6
+
7
+ HERE
8
+
9
+ unless File.exists? CONFIG_FILE
10
+ abort "Usage: Put a target location in .linknew and run the script"
11
+ end
12
+
13
+ folder = IO.read(CONFIG_FILE).strip
14
+ unless File.exists? folder
15
+ abort "The folder \"#{folder}\" does not exist"
16
+ end
17
+ unless File.directory? folder
18
+ abort "The folder \"#{folder}\" is not a directory"
19
+ end
20
+
21
+ Linknew::Linknew.new(folder).execute
@@ -0,0 +1,27 @@
1
+ require "linknew/version"
2
+ require "sqlite3"
3
+
4
+ require 'linknew/database'
5
+
6
+ module Linknew
7
+ class Linknew
8
+ def initialize folder
9
+ @folder = folder
10
+ abort("Target folder does not exist") unless File.exists? folder
11
+ end
12
+
13
+ def execute
14
+ db = Database.new
15
+ Dir.foreach(@folder) do |file|
16
+ next if file == "." || file == ".."
17
+ file = File.join(@folder, file)
18
+
19
+ unless db.has_file? file
20
+ puts "Linking #{File.basename(file)}"
21
+ File.symlink(file, File.basename(file))
22
+ db.enter_file(file)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ require 'linknew/errors'
2
+ require 'digest'
3
+
4
+ module Linknew
5
+ class Database
6
+ def initialize
7
+ @db = SQLite3::Database.new ".linknew.db"
8
+ @db.execute "CREATE TABLE IF NOT EXISTS files (md5name char(32))"
9
+ @db.execute "CREATE INDEX IF NOT EXISTS files_md5name ON files (md5name)"
10
+
11
+ @has_file_stmt = @db.prepare("SELECT EXISTS(SELECT 1 FROM files WHERE md5name = ? LIMIT 1)")
12
+ @enter_file_stmt = @db.prepare("INSERT INTO files VALUES (?)")
13
+ end
14
+
15
+ def has_file? file
16
+ @has_file_stmt.execute(filehash(file)).next[0] == 1
17
+ end
18
+
19
+ def enter_file file
20
+ @enter_file_stmt.execute(filehash(file))
21
+ end
22
+
23
+ private
24
+
25
+ def filehash file
26
+ ::Digest::MD5.hexdigest(File.basename(file))
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,4 @@
1
+ module Linknew
2
+ class Error < StandardError; end
3
+ class FileNotFoundError < Error; end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Linknew
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'linknew/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "linknew"
8
+ spec.version = Linknew::VERSION
9
+ spec.authors = ["Simon Kohlmeyer"]
10
+ spec.email = ["simon.kohlmeyer@gmail.com"]
11
+ spec.summary = %q{Links to files in a directory once}
12
+ #spec.description = %q{TODO: Write a longer description. Optional.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "sqlite3", "~>1.3"
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Linknew do
4
+ it 'has a version number' do
5
+ expect(Linknew::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'does something useful' do
9
+ expect(false).to eq(true)
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'linknew'
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: linknew
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Simon Kohlmeyer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sqlite3
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - simon.kohlmeyer@gmail.com
72
+ executables:
73
+ - linknew
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".ruby-version"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/linknew
86
+ - lib/linknew.rb
87
+ - lib/linknew/database.rb
88
+ - lib/linknew/errors.rb
89
+ - lib/linknew/version.rb
90
+ - linknew.gemspec
91
+ - spec/linknew_spec.rb
92
+ - spec/spec_helper.rb
93
+ homepage: ''
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.2.2
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Links to files in a directory once
117
+ test_files:
118
+ - spec/linknew_spec.rb
119
+ - spec/spec_helper.rb