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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6b47f24fe85a20396499477fa1663d2a8f1ac32
4
- data.tar.gz: 7108e85348a4ff49bb16c466adbf5343582de3e7
3
+ metadata.gz: 358bef6f4f3581344942ab11c089a87b9e03ba4b
4
+ data.tar.gz: 18a468b78f55394419e517c024e096c38272b209
5
5
  SHA512:
6
- metadata.gz: 4fc3bb757348b5277e12f527592a336790deaacf934854b33c3236fcd0758cbb9d00ccedaf9cb27557eb6606851448778c542fa4ef06d465d13cfd9e2878a037
7
- data.tar.gz: fea83bc70af99ed9d8f8583a20e388410a02ce1c43eb97e8b8470d5b79d3303791866b0dfd39f3bdbec5a47bda251b002e5d2a5de8f661a85fa06528ca1ab094
6
+ metadata.gz: 5e39bef0c52d8e60ca185bfd2e5640339fa3e7c9c6e4ef73d9354d4c9a5c25e19ba78a5852c0a1ed1dc3597ee0effbda41128b2c805dfc7f6e832cab1c5a7ce8
7
+ data.tar.gz: d3239bfede0bb9bc05b46d06084cb06472efa8ccc668b2449c65e15efe11e5ab498f6374988d3cf54c55aeaf72c4f74625be814bb0549bb77ee334e8a2e376aa
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- script_utils (0.0.3)
4
+ script_utils (0.0.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
- def files(dir)
12
- dir = dir[0...-1] if dir.end_with?('/')
13
- dir = "#{dir}/*"
14
- Dir[dir].select { |f| File.file?(f) }
15
- end
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
- def file_names(dir)
18
- files(dir).map { |f| File.basename(f) }
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,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'script_utils'
3
- gem.version = '0.0.3'
3
+ gem.version = '0.0.4'
4
4
  gem.summary = 'script helpers'
5
5
  gem.author = 'Lihan Li'
6
6
  gem.email = 'frankieteardrop@gmail.com'
@@ -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("spec/test_dir")).to eq(["spec/test_dir/file"])
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("spec/test_dir/")).to eq(["spec/test_dir/file"])
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('spec/test_dir')).to eq(['file'])
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.3
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-04-28 00:00:00.000000000 Z
11
+ date: 2015-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec