fs_layer 0.0.2
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.
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +8 -0
- data/fs_layer.gemspec +23 -0
- data/lib/fs_layer.rb +9 -0
- data/lib/fs_layer/api.rb +29 -0
- data/lib/fs_layer/file.rb +39 -0
- data/lib/fs_layer/index.rb +11 -0
- data/lib/fs_layer/link.rb +14 -0
- data/lib/fs_layer/version.rb +3 -0
- data/spec/cabinet_spec.rb +32 -0
- data/spec/file_spec.rb +37 -0
- data/spec/index_spec.rb +13 -0
- data/spec/spec_helper.rb +17 -0
- metadata +122 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.3@cabinet --create
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Aldric Giacomoni
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# FSLayer
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'fs_layer'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install fs_layer
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
FSLayer.retrieve file
|
22
|
+
FSLayer.insert file
|
23
|
+
FSLayer.delete file
|
24
|
+
FSLayer.config do |c|
|
25
|
+
c.fake = true
|
26
|
+
c.log = true
|
27
|
+
c.logger = Logger.new
|
28
|
+
end
|
29
|
+
FSLayer.link('file').to('symlink_destination')
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
38
|
+
|
39
|
+
### possible vocabulary
|
40
|
+
|
41
|
+
* file / folder
|
42
|
+
* hanging file
|
43
|
+
* shredder
|
44
|
+
* recycle bin
|
45
|
+
* marker
|
46
|
+
* reference
|
47
|
+
* index
|
48
|
+
* label
|
49
|
+
* lock
|
data/Rakefile
ADDED
data/fs_layer.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fs_layer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "fs_layer"
|
8
|
+
gem.version = FSLayer::VERSION
|
9
|
+
gem.authors = ["Aldric Giacomoni"]
|
10
|
+
gem.email = ["trevoke@gmail.com"]
|
11
|
+
gem.description = %q{Friendly file/directory interface. Secretary not included.}
|
12
|
+
gem.summary = %q{An interface for files and directories, because using and mocking File/FileUtils is just wrong.}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'rspec', '>= 2.12.0'
|
22
|
+
gem.add_development_dependency 'cucumber'
|
23
|
+
end
|
data/lib/fs_layer.rb
ADDED
data/lib/fs_layer/api.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module FSLayer
|
2
|
+
class << self
|
3
|
+
|
4
|
+
def fake_it
|
5
|
+
@fake = true
|
6
|
+
end
|
7
|
+
|
8
|
+
def keep_it_real
|
9
|
+
@fake = false
|
10
|
+
end
|
11
|
+
|
12
|
+
def fake?
|
13
|
+
@fake
|
14
|
+
end
|
15
|
+
|
16
|
+
def insert file
|
17
|
+
FSLayer::File.add file
|
18
|
+
end
|
19
|
+
|
20
|
+
def has? file_object
|
21
|
+
Index.known_files.include? file_object
|
22
|
+
end
|
23
|
+
|
24
|
+
def link file
|
25
|
+
FSLayer::Link.new(FSLayer::File.add(file))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module FSLayer
|
4
|
+
class File
|
5
|
+
def self.add file
|
6
|
+
FileUtils.touch file unless FSLayer.fake?
|
7
|
+
Index.organize file
|
8
|
+
new file
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.retrieve filename
|
12
|
+
new filename
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize file
|
16
|
+
@file = file
|
17
|
+
end
|
18
|
+
|
19
|
+
def name
|
20
|
+
::File.basename @file
|
21
|
+
end
|
22
|
+
|
23
|
+
def exist?
|
24
|
+
::File.exists? @file
|
25
|
+
end
|
26
|
+
|
27
|
+
def symlink?
|
28
|
+
::File.symlink? @file
|
29
|
+
end
|
30
|
+
|
31
|
+
def destination
|
32
|
+
Pathname.new(@file).realpath.to_s
|
33
|
+
end
|
34
|
+
|
35
|
+
def path
|
36
|
+
@file
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module FSLayer
|
2
|
+
class Link
|
3
|
+
attr_reader :file
|
4
|
+
|
5
|
+
def initialize file
|
6
|
+
@file = file
|
7
|
+
end
|
8
|
+
|
9
|
+
def to symlink_destination
|
10
|
+
::File.symlink(file.path, symlink_destination) unless FSLayer.fake?
|
11
|
+
FSLayer::File.add(symlink_destination)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require File.expand_path File.join(File.dirname(__FILE__), '..', 'lib', 'fs_layer')
|
3
|
+
|
4
|
+
describe FSLayer do
|
5
|
+
subject { FSLayer }
|
6
|
+
|
7
|
+
describe "Faking it" do
|
8
|
+
|
9
|
+
before do
|
10
|
+
subject.fake_it
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
subject.keep_it_real
|
15
|
+
end
|
16
|
+
|
17
|
+
it "does not really create files" do
|
18
|
+
file = subject.insert '/tmp/file'
|
19
|
+
file.should be_an_instance_of FSLayer::File
|
20
|
+
subject.has?('/tmp/file').should be_true
|
21
|
+
file.should_not exist
|
22
|
+
end
|
23
|
+
|
24
|
+
it "does not really create symlinks" do
|
25
|
+
subject.insert '/tmp/file1'
|
26
|
+
file = subject.link('/tmp/file1').to('/tmp/file2')
|
27
|
+
file.should be_an_instance_of FSLayer::File
|
28
|
+
file.path.should eq '/tmp/file2'
|
29
|
+
::File.exist?(file.path).should be_false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/file_spec.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative "../lib/fs_layer.rb"
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module FSLayer
|
5
|
+
describe File do
|
6
|
+
let(:file) { "filename" }
|
7
|
+
|
8
|
+
context "that exists" do
|
9
|
+
before { File.add file }
|
10
|
+
after { FileUtils.rm_f file }
|
11
|
+
|
12
|
+
context "has relevant information" do
|
13
|
+
subject { File.retrieve file }
|
14
|
+
its(:name) { should eq file }
|
15
|
+
its(:exist?) { should be_true }
|
16
|
+
its(:symlink?) { should be_false }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
context "that does not exist" do
|
22
|
+
before do
|
23
|
+
FSLayer.fake_it
|
24
|
+
File.add file
|
25
|
+
end
|
26
|
+
after do
|
27
|
+
FSLayer.keep_it_real
|
28
|
+
end
|
29
|
+
|
30
|
+
context "has relevant information" do
|
31
|
+
subject { File.retrieve file }
|
32
|
+
its(:name) { should eq file}
|
33
|
+
its(:exist?) { should be_false }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/index_spec.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative '../lib/fs_layer.rb'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module FSLayer
|
5
|
+
describe Index do
|
6
|
+
let(:file) { 'some_file_name' }
|
7
|
+
after { FileUtils.rm_f file }
|
8
|
+
it "adds them to the list of managed files" do
|
9
|
+
File.add file
|
10
|
+
Index.known_files.should include(file)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
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"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fs_layer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Aldric Giacomoni
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
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: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.12.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: 2.12.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: cucumber
|
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
|
+
description: Friendly file/directory interface. Secretary not included.
|
63
|
+
email:
|
64
|
+
- trevoke@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- .rvmrc
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE.txt
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- fs_layer.gemspec
|
77
|
+
- lib/fs_layer.rb
|
78
|
+
- lib/fs_layer/api.rb
|
79
|
+
- lib/fs_layer/file.rb
|
80
|
+
- lib/fs_layer/index.rb
|
81
|
+
- lib/fs_layer/link.rb
|
82
|
+
- lib/fs_layer/version.rb
|
83
|
+
- spec/cabinet_spec.rb
|
84
|
+
- spec/file_spec.rb
|
85
|
+
- spec/index_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
homepage: ''
|
88
|
+
licenses: []
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
hash: -1559428345412472295
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
hash: -1559428345412472295
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.24
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: An interface for files and directories, because using and mocking File/FileUtils
|
117
|
+
is just wrong.
|
118
|
+
test_files:
|
119
|
+
- spec/cabinet_spec.rb
|
120
|
+
- spec/file_spec.rb
|
121
|
+
- spec/index_spec.rb
|
122
|
+
- spec/spec_helper.rb
|