dusel 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 +14 -0
- data/LICENSE.txt +20 -0
- data/README.markdown +17 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/lib/dusel.rb +40 -0
- data/lib/dusel/instance_methods.rb +58 -0
- data/lib/dusel/version.rb +3 -0
- data/spec/dusel_spec.rb +110 -0
- data/spec/spec_helper.rb +11 -0
- metadata +117 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
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", "~> 2.3.0"
|
10
|
+
gem "yard", "~> 0.6.0"
|
11
|
+
gem "bundler", "~> 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.6.4"
|
13
|
+
gem "rcov", ">= 0"
|
14
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Johannes Huning
|
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.markdown
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Dusel
|
2
|
+
|
3
|
+
Tiny DSL to create (temporary) files and folders
|
4
|
+
|
5
|
+
## Contributing to Dusel
|
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) 2011 Johannes Huning. See LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
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
|
17
|
+
# for more options
|
18
|
+
gem.name = "dusel"
|
19
|
+
gem.homepage = "https://github.com/johannesh/dusel"
|
20
|
+
gem.license = "MIT"
|
21
|
+
gem.summary = %Q{Tiny DSL to create (temporary) files and folders}
|
22
|
+
gem.description = %Q{Dusel is a tiny DSL to create (nested) folders and
|
23
|
+
directories}
|
24
|
+
gem.email = "hi@johanneshuning.com"
|
25
|
+
gem.authors = ["Johannes Huning"]
|
26
|
+
# dependencies defined in Gemfile
|
27
|
+
end
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
29
|
+
|
30
|
+
require 'rspec/core'
|
31
|
+
require 'rspec/core/rake_task'
|
32
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
33
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
34
|
+
end
|
35
|
+
|
36
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
37
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
38
|
+
spec.rcov = true
|
39
|
+
end
|
40
|
+
|
41
|
+
task :default => :spec
|
42
|
+
|
43
|
+
require 'yard'
|
44
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/dusel.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
libdir = File.dirname(__FILE__)
|
2
|
+
$:.unshift libdir unless $:.include?(libdir)
|
3
|
+
|
4
|
+
require 'tmpdir'
|
5
|
+
require 'securerandom'
|
6
|
+
|
7
|
+
require 'dusel/instance_methods'
|
8
|
+
require 'dusel/version'
|
9
|
+
|
10
|
+
module Dusel
|
11
|
+
def self.dir(name = nil, parent = nil, &block)
|
12
|
+
parent ||= Dir.mktmpdir()
|
13
|
+
parent = parent.path if parent.kind_of?(Dir)
|
14
|
+
Dir.open(parent).dir(name, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.file(name = nil, parent = nil, &block)
|
18
|
+
parent ||= Dir.mktmpdir()
|
19
|
+
parent = parent.path if parent.kind_of?(Dir)
|
20
|
+
Dir.open(parent).file(name, &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.rm!(tree)
|
24
|
+
tree.rm!
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.included(base)
|
28
|
+
base.__send__(:include, InstanceMethods)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def self.random_name(length = 16)
|
34
|
+
SecureRandom.hex(length / 2)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Dir
|
39
|
+
include Dusel
|
40
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'tmpdir'
|
2
|
+
|
3
|
+
module Dusel
|
4
|
+
module InstanceMethods
|
5
|
+
def dir(name = nil, &block)
|
6
|
+
new_path = __named_path(name)
|
7
|
+
Dir.mkdir new_path
|
8
|
+
new_dir = Dir.new(new_path)
|
9
|
+
|
10
|
+
@__dusel_dirs ||= []
|
11
|
+
@__dusel_dirs << new_dir
|
12
|
+
|
13
|
+
if block
|
14
|
+
if block.arity < 1
|
15
|
+
new_dir.instance_eval(&block)
|
16
|
+
new_dir
|
17
|
+
else
|
18
|
+
block.call(new_dir)
|
19
|
+
end
|
20
|
+
else
|
21
|
+
new_dir
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def file(name = nil, &block)
|
26
|
+
new_path = __named_path(name)
|
27
|
+
new_file = File.open(new_path, "w+")
|
28
|
+
|
29
|
+
@__dusel_files ||= []
|
30
|
+
@__dusel_files << new_file
|
31
|
+
|
32
|
+
if block
|
33
|
+
if block.arity < 1
|
34
|
+
new_file.write(block.call())
|
35
|
+
new_file.rewind
|
36
|
+
new_file
|
37
|
+
else
|
38
|
+
block.call(new_file)
|
39
|
+
end
|
40
|
+
else
|
41
|
+
new_file
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def rm!
|
46
|
+
@__dusel_files.each { |file| File.delete(file.path) } if @__dusel_files
|
47
|
+
@__dusel_dirs.each { |dir| dir.rm! } if @__dusel_dirs
|
48
|
+
Dir.rmdir(self.path())
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def __named_path(name = nil)
|
54
|
+
name ||= Dusel.__send__(:random_name)
|
55
|
+
File.join(self.path, name)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/spec/dusel_spec.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe 'Dusel' do
|
4
|
+
describe '.dir' do
|
5
|
+
it "should create a folder inside a random directory if no parent given" do
|
6
|
+
first_path = Dusel.dir { |d| File.dirname(d.path) }
|
7
|
+
second_path = Dusel.dir { |d| File.dirname(d.path) }
|
8
|
+
first_path.should_not eq(second_path)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should create a folder inside the given parent" do
|
12
|
+
Dusel.dir { |outer|
|
13
|
+
Dusel.dir(name = nil, parent = outer) { |d|
|
14
|
+
File.dirname(d.path).should eq(outer.path)
|
15
|
+
}
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '.file' do
|
21
|
+
it "should create a file inside a random directory if no parent given" do
|
22
|
+
first_path = Dusel.file { |f| File.dirname(f.path) }
|
23
|
+
second_path = Dusel.file { |f| File.dirname(f.path) }
|
24
|
+
first_path.should_not eq(second_path)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should create a file inside the given parent" do
|
28
|
+
Dusel.dir { |outer|
|
29
|
+
Dusel.file(name = nil, parent = outer) { |f|
|
30
|
+
File.dirname(f.path).should eq(outer.path)
|
31
|
+
}
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".random_name" do
|
37
|
+
it "should generate random strings" do
|
38
|
+
Dusel.__send__(:random_name).should_not eq(Dusel.__send__(:random_name))
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should generate string of the given size" do
|
42
|
+
Dusel.__send__(:random_name, 78).length.should eq(78)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#dir' do
|
47
|
+
it "should create a folder with random name if none given" do
|
48
|
+
Dusel.dir { |d|
|
49
|
+
first_path = d.dir.path
|
50
|
+
second_path = d.dir.path
|
51
|
+
first_path.should_not eq(second_path)
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should create a folder with given name" do
|
56
|
+
name = "foldername"
|
57
|
+
Dusel.dir { |outer|
|
58
|
+
outer.dir(name) { |d| File.basename(d.path).should eq(name) }
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should create a folder inside given parent" do
|
63
|
+
Dusel.dir { |outer|
|
64
|
+
outer.dir { |inner| File.dirname(inner.path).should eq(outer.path) }
|
65
|
+
}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#file' do
|
70
|
+
it "should create a file with random name if none given" do
|
71
|
+
Dusel.dir { |d|
|
72
|
+
first_path = d.file.path
|
73
|
+
second_path = d.file.path
|
74
|
+
first_path.should_not eq(second_path)
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should create a file with given name" do
|
79
|
+
filename = "filename"
|
80
|
+
Dusel.dir { |d|
|
81
|
+
d.file(filename) { |f| File.basename(f.path).should eq(filename) }
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should create a file with the given contents" do
|
86
|
+
contents = "contents"
|
87
|
+
Dusel.dir { |d|
|
88
|
+
file = d.file { contents }
|
89
|
+
file.read.should eq(contents)
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should create a file inside the given parent" do
|
94
|
+
Dusel.dir { |d|
|
95
|
+
d.file { |f| File.dirname(f.path).should eq(d.path) }
|
96
|
+
}
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#remove' do
|
101
|
+
it "should close and remove all directories and files recusively" do
|
102
|
+
dir = Dusel.dir {
|
103
|
+
file
|
104
|
+
dir { file }
|
105
|
+
}
|
106
|
+
Dusel.rm!(dir)
|
107
|
+
File.exist?(dir.path).should be_false
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'dusel'
|
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
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dusel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Johannes Huning
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-06 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &18440160 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.3.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *18440160
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: yard
|
27
|
+
requirement: &18439580 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.6.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *18439580
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bundler
|
38
|
+
requirement: &18438900 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.0.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *18438900
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: jeweler
|
49
|
+
requirement: &18438240 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.6.4
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *18438240
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rcov
|
60
|
+
requirement: &18437660 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *18437660
|
69
|
+
description: ! "Dusel is a tiny DSL to create (nested) folders and\n directories"
|
70
|
+
email: hi@johanneshuning.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files:
|
74
|
+
- LICENSE.txt
|
75
|
+
- README.markdown
|
76
|
+
files:
|
77
|
+
- .document
|
78
|
+
- .rspec
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.markdown
|
82
|
+
- Rakefile
|
83
|
+
- VERSION
|
84
|
+
- lib/dusel.rb
|
85
|
+
- lib/dusel/instance_methods.rb
|
86
|
+
- lib/dusel/version.rb
|
87
|
+
- spec/dusel_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: https://github.com/johannesh/dusel
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
hash: -602893548499290189
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.10
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: Tiny DSL to create (temporary) files and folders
|
117
|
+
test_files: []
|