code_lister 0.1.5 → 0.1.6

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: 3b8a6cc82b42cda1a7b1c546f0ee7da1bce896d9
4
- data.tar.gz: cbfaaa128b8c8a81415c9a1db26dce4f1726fc21
3
+ metadata.gz: dfde1ca13e9439d3c3a32f17e99162355cb98dee
4
+ data.tar.gz: 105d46aaeb7abb5bfd55d3c1b539474fe3614037
5
5
  SHA512:
6
- metadata.gz: 09eec3266b90072fd591dedaea2b4c66a31ca92cc074dcaaac386fa1aa6649906619ac2d6961c1b44ebe0ac3883b8dade2d118b93a74662d8624a164775518fb
7
- data.tar.gz: c8ba84ca0e61549de5420cc1c14ca3e7728b5704080405ee035ad64e9c1f46b5051db7bdbd6a361932d773044d4caa00024a1b1a8c6f5a8cfe920b4ebe25cd37
6
+ metadata.gz: 745702c17b9c5c68649907f280fc33e0955365382d5b760454c475a8fdce17e12881c7c0952f5b3110aa6a8574a4cb0739580e5c8ea2c74a9eb4235e73e8a37f
7
+ data.tar.gz: d3c35b8ba4bc9209726bb169409dc193f1df13e63f219475e430190b3662a7762b159eb4ef3b4a10c822e8c93e09b65ee32c7e2d5dba3317677740a906954080
@@ -1,5 +1,11 @@
1
1
  ### Changelogs
2
2
 
3
+ #### 0.1.6
4
+
5
+ - Add internal api for getting input files from shell command
6
+ - Update `agile_utils` to 0.1.14
7
+ - Minor code cleanup
8
+
3
9
  #### 0.1.5
4
10
 
5
11
  - Update the rspec folder structure
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
24
24
  spec.require_paths = ["lib"]
25
25
  spec.add_runtime_dependency "thor", "~> 0.19"
26
- spec.add_runtime_dependency "agile_utils", "~> 0.1"
26
+ spec.add_runtime_dependency "agile_utils", "~> 0.1.4"
27
27
  spec.add_development_dependency "bundler", "~> 1.6"
28
28
  spec.add_development_dependency "rake", "~> 10.3"
29
29
  spec.add_development_dependency "rspec", "~> 2.14"
@@ -1,3 +1,4 @@
1
+ require 'agile_utils'
1
2
  module CodeLister
2
3
  CustomError = Class.new(StandardError)
3
4
  class << self
@@ -10,30 +11,17 @@ module CodeLister
10
11
  # 'find ~/Desktop/pdfkit -type f -iname "*.rb" | grep -v spec'
11
12
  #
12
13
  # @param [String] command the input command to be executed in the shell
13
- # @param [String] base_dir the starting directory
14
14
  # @return [Array<String>] file list or empty list if the shell command is not valid
15
- def files_from_command(command, base_dir = ".")
15
+ def files_from_command(command)
16
16
  files = AgileUtils::Helper.shell(command.split(" ")).split(/\n/)
17
- # Adapt the result and make sure that it starts with "./"
18
- # like the result from 'CodeLister.files()' method
19
- files.map! do |file|
20
- if base_dir
21
- if file =~ /^\./
22
- File.expand_path(file).gsub(File.expand_path(base_dir), ".")
23
- else
24
- File.expand_path(file).gsub(File.expand_path(base_dir), ".")
25
- end
26
- end
27
- end
17
+ files.map! { |file| File.expand_path(file) }
18
+ # Some command result in the deleted files (e.g. git diff --name-only HEAD~n)
28
19
  files.delete_if do |file|
29
- !File.exist?([
30
- File.expand_path(base_dir),
31
- file.gsub(/^\./, "")
32
- ].join(""))
20
+ !File.exist?(file)
33
21
  end
34
22
  files
35
23
  rescue RuntimeError => e
36
- # just return the empty list, if the user specified invalid command
24
+ # return empty list for invalid command
37
25
  return []
38
26
  end
39
27
 
@@ -63,11 +51,9 @@ module CodeLister
63
51
 
64
52
  files_with_extension = Dir.glob(File.join(base_dir, wildcard, "*.{#{exts.join(",")}}"))
65
53
  files_without_extension = no_extension_files(base_dir, wildcard, non_exts)
66
- # remove the 'base_dir' with .
67
- files_with_extension.each { |f| f.gsub!(base_dir, ".") }
68
- files_without_extension.each { |f| f.gsub!(base_dir, ".") }
69
- # combine the result
70
- (files_with_extension + files_without_extension).sort
54
+ # Replace prefix directory with just "."
55
+ files = (files_with_extension + files_without_extension)
56
+ files.map! { |file| file.gsub(base_dir, ".") }.sort
71
57
  end
72
58
 
73
59
  # Filter out the list based on simple criteria
@@ -84,13 +70,22 @@ module CodeLister
84
70
  exc_words: [],
85
71
  ignore_case: true
86
72
  }.merge(args)
87
-
88
73
  take_any!(file_list, opts)
89
74
  drop_any!(file_list, opts)
90
-
91
75
  file_list
92
76
  end
93
77
 
78
+ # Remove each prefix string from a given list of string
79
+ #
80
+ # @param [Array<String>] files list of file path/name
81
+ # @param [String] base_dir
82
+ # @return [Array<String>] list of files with the prefix replaced by "."
83
+ def remove_prefix(files, prefix)
84
+ prefix = File.expand_path(prefix) if prefix
85
+ files.map! { |file| prefix ? file.gsub(prefix, ".") : file }
86
+ files
87
+ end
88
+
94
89
  private
95
90
 
96
91
  # List files that do not have the extension
@@ -107,13 +102,11 @@ module CodeLister
107
102
  def take_any!(file_list, args = {})
108
103
  words = args[:inc_words]
109
104
  ignore_case = args[:ignore_case]
110
-
111
105
  unless words.empty?
112
106
  file_list.select! do |file|
113
107
  matched_any?(words, file, ignore_case)
114
108
  end
115
109
  end
116
-
117
110
  file_list
118
111
  end
119
112
 
@@ -1,3 +1,3 @@
1
1
  module CodeLister
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_lister
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burin Choomnuan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-19 00:00:00.000000000 Z
11
+ date: 2014-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.1'
33
+ version: 0.1.4
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.1'
40
+ version: 0.1.4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement