script_utils 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/script_utils.rb +14 -7
- data/script_utils.gemspec +1 -1
- data/spec/script_utils/script_utils_spec.rb +17 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 358bef6f4f3581344942ab11c089a87b9e03ba4b
|
4
|
+
data.tar.gz: 18a468b78f55394419e517c024e096c38272b209
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e39bef0c52d8e60ca185bfd2e5640339fa3e7c9c6e4ef73d9354d4c9a5c25e19ba78a5852c0a1ed1dc3597ee0effbda41128b2c805dfc7f6e832cab1c5a7ce8
|
7
|
+
data.tar.gz: d3239bfede0bb9bc05b46d06084cb06472efa8ccc668b2449c65e15efe11e5ab498f6374988d3cf54c55aeaf72c4f74625be814bb0549bb77ee334e8a2e376aa
|
data/Gemfile.lock
CHANGED
data/lib/script_utils.rb
CHANGED
@@ -8,13 +8,20 @@ module ScriptUtils
|
|
8
8
|
raise if ensure_success && !$?.success?
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
%w[files directories].each do |type|
|
12
|
+
singular = type == 'files' ? 'file' : 'directory'
|
13
|
+
|
14
|
+
define_method(type) do |dir|
|
15
|
+
dir = dir[0...-1] if dir.end_with?('/')
|
16
|
+
dir = "#{dir}/*"
|
17
|
+
|
18
|
+
Dir[dir].find_all do |file_or_dir|
|
19
|
+
File.public_send("#{singular}?", file_or_dir)
|
20
|
+
end
|
21
|
+
end
|
16
22
|
|
17
|
-
|
18
|
-
|
23
|
+
define_method("#{singular}_names") do |dir|
|
24
|
+
public_send(type, dir).map { |f| File.basename(f) }
|
25
|
+
end
|
19
26
|
end
|
20
27
|
end
|
data/script_utils.gemspec
CHANGED
@@ -1,23 +1,37 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe ScriptUtils do
|
4
|
+
let(:test_dir) { 'spec/test_dir' }
|
5
|
+
|
4
6
|
describe '#files' do
|
5
7
|
context 'without a trailing slash' do
|
6
8
|
it 'should list the files in a directory' do
|
7
|
-
expect(ScriptUtils.files(
|
9
|
+
expect(ScriptUtils.files(test_dir)).to eq(["spec/test_dir/file"])
|
8
10
|
end
|
9
11
|
end
|
10
12
|
|
11
13
|
context 'with a trailing slash' do
|
12
14
|
it 'should list the files in a directory' do
|
13
|
-
expect(ScriptUtils.files("
|
15
|
+
expect(ScriptUtils.files("#{test_dir}/")).to eq(["spec/test_dir/file"])
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
20
|
+
describe '#directories' do
|
21
|
+
it 'should list all the directories' do
|
22
|
+
expect(ScriptUtils.directories(test_dir)).to eq(["spec/test_dir/dog"])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
18
26
|
describe '#file_names' do
|
19
27
|
it 'should list the files names' do
|
20
|
-
expect(ScriptUtils.file_names(
|
28
|
+
expect(ScriptUtils.file_names(test_dir)).to eq(['file'])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#directory_names' do
|
33
|
+
it 'should list the dir names' do
|
34
|
+
expect(ScriptUtils.directory_names(test_dir)).to eq(['dog'])
|
21
35
|
end
|
22
36
|
end
|
23
37
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: script_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lihan Li
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|