fast 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.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/fast.gemspec +23 -0
- data/lib/fast/file.rb +28 -0
- data/lib/fast/version.rb +3 -0
- data/lib/fast.rb +63 -0
- metadata +80 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/fast.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "fast/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "fast"
|
7
|
+
s.version = Fast::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Xavier Via"]
|
10
|
+
s.email = ["xavierviacanel@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{DSL for file system interaction}
|
13
|
+
s.description = %q{DSL for file system interaction}
|
14
|
+
|
15
|
+
s.rubyforge_project = "fast"
|
16
|
+
|
17
|
+
s.add_dependency "metafun"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
data/lib/fast/file.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Fast
|
2
|
+
# File handling class.
|
3
|
+
class File
|
4
|
+
# Appends the passed content to the file `path`
|
5
|
+
def append path, content
|
6
|
+
::File.open path, "a" do |handler|
|
7
|
+
handler.write content
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Deletes the file (wrapper for `File.unlink <path>`)
|
12
|
+
def delete path
|
13
|
+
::File.unlink path
|
14
|
+
end
|
15
|
+
|
16
|
+
alias :destroy :delete
|
17
|
+
alias :unlink :delete
|
18
|
+
alias :del :delete
|
19
|
+
|
20
|
+
def self.call *args
|
21
|
+
if args.empty?
|
22
|
+
File.new
|
23
|
+
else
|
24
|
+
::File.read args.shift
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/fast/version.rb
ADDED
data/lib/fast.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "metafun/delegator"
|
2
|
+
|
3
|
+
require "fast/file"
|
4
|
+
|
5
|
+
module Fast
|
6
|
+
# Returns the list of entries in the directory
|
7
|
+
# Options:
|
8
|
+
#
|
9
|
+
# `:extension => ".jpg"` # Filters returned files by extension
|
10
|
+
# `:strip_extension => true` # If an `:extension` is given, returns the
|
11
|
+
# # entries without it
|
12
|
+
def self.dir path, options = nil
|
13
|
+
if options
|
14
|
+
if options[:extension]
|
15
|
+
filtered = []
|
16
|
+
Dir.entries(path).each do |entry|
|
17
|
+
if entry.end_with? ".#{options[:extension]}"
|
18
|
+
if options[:strip_extension]
|
19
|
+
filtered << entry[0..-("#{options[:extension]}".length)-2]
|
20
|
+
else
|
21
|
+
filtered << entry
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
return filtered
|
26
|
+
end
|
27
|
+
else
|
28
|
+
Dir.entries path
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Like `dir`, but creates the directory if it does not exist
|
33
|
+
def self.dir! path, options = nil
|
34
|
+
mkdir path unless dir? path
|
35
|
+
dir path, options
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns true if a directory named `path` exists, false otherwise.
|
39
|
+
# (wrapper for `File.directory? <path>`)
|
40
|
+
def self.dir? path
|
41
|
+
::File.directory? path
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns an instance of Fast::File and passed all methods
|
45
|
+
# and arguments to it
|
46
|
+
def self.file *args
|
47
|
+
Fast::File.call *args
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def self.mkdir path
|
52
|
+
path.split("/").each do |part|
|
53
|
+
route ||= part
|
54
|
+
Dir.mkdir route unless route == "" || ::File.directory?( route )
|
55
|
+
route += "/#{path}"
|
56
|
+
end
|
57
|
+
# Dir.mkdir path # It seems this was redundant
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
include Metafun::Delegator
|
62
|
+
|
63
|
+
delegate Fast, :dir, :dir?, :dir!, :file, :from
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fast
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Xavier Via
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-11-11 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: metafun
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
description: DSL for file system interaction
|
33
|
+
email:
|
34
|
+
- xavierviacanel@gmail.com
|
35
|
+
executables: []
|
36
|
+
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files: []
|
40
|
+
|
41
|
+
files:
|
42
|
+
- .gitignore
|
43
|
+
- Gemfile
|
44
|
+
- Rakefile
|
45
|
+
- fast.gemspec
|
46
|
+
- lib/fast.rb
|
47
|
+
- lib/fast/file.rb
|
48
|
+
- lib/fast/version.rb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: ""
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project: fast
|
75
|
+
rubygems_version: 1.3.6
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: DSL for file system interaction
|
79
|
+
test_files: []
|
80
|
+
|