code_lister 0.1.1 → 0.1.2

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: 5bc886d3f4e601c170e30c41a311f61e37bfecac
4
- data.tar.gz: e909544107643a2bf2b816edc3bf395f807bbc25
3
+ metadata.gz: 23c2c55f6c39b00ae60f077b1084bc9953b4f79a
4
+ data.tar.gz: 381925655a9501099259f6faddad7d97644fb180
5
5
  SHA512:
6
- metadata.gz: 38ced4389d381c0826fefc77c3733db019f4c3a2a8a086d4602559e4f5d1de2124b9daad61c214cdf594a3d665826dafacb4612ab68ea5c34be43e7abb8255af
7
- data.tar.gz: 3c2ae7129c7db2ebab95d10a40c1563041d9ed2e319f5fd0d04fc32b001352b742f54f540657e59f7d68fa5fbc963c5c3cb3c7a13564b512f23cf75fb6e2a7b7
6
+ metadata.gz: 0a216909fc91b708f6f400553275b24a46ab757a62c73959b337fdcba1c06709d5c51475a1d30a12561b6f92da118aff9c3cec0fc98f398288f451769f0271c4
7
+ data.tar.gz: c8c0b36b8c0331d7c2bf77b96306d2d803bf748e2dcb7df40a1d47f85dbf157f9d22c441fe69dfb2d442ab62bb015a86d0776526bc2144d6c6c134b0017411db
data/.rubocop.yml CHANGED
@@ -52,7 +52,7 @@ HashSyntax:
52
52
 
53
53
  # No spaces inside hash literals
54
54
  SpaceInsideHashLiteralBraces:
55
- EnforcedStyle: no_space
55
+ EnforcedStyle: space
56
56
 
57
57
  # Allow dots at the end of lines
58
58
  DotPosition:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ### Changelogs
2
2
 
3
+ #### 0.1.2
4
+
5
+ - Improve documentation
6
+ - Update style for rubocop and update to rubocop 0.23.x
7
+
3
8
  #### 0.1.1
4
9
 
5
10
  - Simplify the CLI interface
data/README.md CHANGED
@@ -40,19 +40,19 @@ Usage/Synopsis:
40
40
 
41
41
  ```
42
42
  Usage:
43
- code_lister [OPTIONS]
43
+ code_lister
44
44
 
45
45
  Options:
46
46
  -b, [--base-dir=BASE_DIR] # Base directory
47
47
  # Default: . (current directory)
48
48
  -e, [--exts=one two three] # List of extensions to search for
49
- -f, [--non-exts=one two three] # List of extensions to search for
50
- -n, [--inc-words=one two three] # List of words to be included in the result
51
- -x, [--exc-words=one two three] # List of words to be excluded from the result
52
- -i, [--ignore-case], [--no-ignore-case] # Match case insensitively
53
- # Default: true
49
+ -f, [--non-exts=one two three] # List of files without extension to search for
50
+ -n, [--inc-words=one two three] # List of words in the filename to be included with the result if any
51
+ -x, [--exc-words=one two three] # List of words in the filename to be excluded from the result if any
52
+ -i, [--ignore-case], [--no-ignore-case] # Ignore the case in the input filename
53
+ # Default: --ignore-case
54
54
  -r, [--recursive], [--no-recursive] # Search for files recursively
55
- # Default: true
55
+ # Default: --recursive
56
56
  -v, [--version], [--no-version] # Display version information
57
57
 
58
58
  List files by extensions, patterns, and simple criteria
data/Rakefile CHANGED
@@ -1,11 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
2
  Bundler::GemHelper.install_tasks
3
-
4
3
  require "rspec/core/rake_task"
5
4
  RSpec::Core::RakeTask.new(:spec)
6
5
 
7
6
  task default: :spec
8
-
9
7
  task :pry do
10
8
  require "pry"
11
9
  require "awesome_print"
@@ -14,3 +12,13 @@ task :pry do
14
12
  ARGV.clear
15
13
  Pry.start
16
14
  end
15
+
16
+ require "rubocop/rake_task"
17
+ desc "Run RuboCop on the lib directory"
18
+ RuboCop::RakeTask.new(:rubocop) do |task|
19
+ task.patterns = ["lib/**/*.rb"]
20
+ # only show the files with failures
21
+ task.formatters = ["files"]
22
+ # don't abort rake on failure
23
+ task.fail_on_error = false
24
+ end
data/code_lister.gemspec CHANGED
@@ -31,5 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "awesome_print", "~> 1.2"
32
32
  spec.add_development_dependency "pry", "~> 0.9"
33
33
  spec.add_development_dependency "fuubar", "~> 1.3"
34
- spec.add_development_dependency "rubocop", "~> 0.20"
34
+ spec.add_development_dependency "rubocop", "~> 0.23"
35
35
  end
@@ -33,13 +33,13 @@ Options:
33
33
  -b, [--base-dir=BASE_DIR] # Base directory
34
34
  # Default: . (current directory)
35
35
  -e, [--exts=one two three] # List of extensions to search for
36
- -f, [--non-exts=one two three] # List of extensions to search for
37
- -n, [--inc-words=one two three] # List of words to be included in the result
38
- -x, [--exc-words=one two three] # List of words to be excluded from the result
39
- -i, [--ignore-case], [--no-ignore-case] # Match case insensitively
40
- # Default: true
36
+ -f, [--non-exts=one two three] # List of files without extension to search for
37
+ -n, [--inc-words=one two three] # List of words in the filename to be included with the result if any
38
+ -x, [--exc-words=one two three] # List of words in the filename to be excluded from the result if any
39
+ -i, [--ignore-case], [--no-ignore-case] # Ignore the case in the input filename
40
+ # Default: --ignore_case
41
41
  -r, [--recursive], [--no-recursive] # Search for files recursively
42
- # Default: true
42
+ # Default: --recursive
43
43
  -v, [--version], [--no-version] # Display version information
44
44
 
45
45
  List files by extensions, patterns, and simple criteria
@@ -50,3 +50,8 @@ List files by extensions, patterns, and simple criteria
50
50
  default_task :usage
51
51
  end
52
52
  end
53
+
54
+ if __FILE__ == $PROGRAM_NAME
55
+ require_relative "../code_lister"
56
+ CodeLister::CLI.start(ARGV)
57
+ end
@@ -1,18 +1,24 @@
1
1
  module CodeLister
2
2
  CustomError = Class.new(StandardError)
3
3
  class << self
4
- # List files base on some extension
4
+ # List files base on multiple simple criteria
5
+ #
6
+ # @param [Hash<Symbol>,<Object>] args argument hash
7
+ # @option args [String] :base_dir the starting directory
8
+ # @option args [Boolean] :recursive flag to indicate if the search will be done recursively
9
+ # @option args [Array<String>] :exts list of file extension to search for (without the dot)
10
+ # @option args [Array<String>] :non_exts list of file without any extension to search for
11
+ # @return [Array<String>] the list of file based on the matching criteria
5
12
  def files(args = {})
6
13
  opts = {
7
- base_dir: Dir.pwd,
14
+ base_dir: Dir.pwd,
8
15
  recursive: false,
9
- exts: [],
10
- non_exts: []
16
+ exts: [],
17
+ non_exts: []
11
18
  }.merge(args)
12
19
 
13
20
  # always expand the path
14
21
  base_dir = File.expand_path(opts[:base_dir])
15
- # base_dir = opts[:base_dir]
16
22
  fail CustomError, "The directory #{base_dir} is not valid or or not readable!" unless File.exist?(base_dir)
17
23
 
18
24
  wildcard = opts[:recursive] ? "**" : ""
@@ -28,7 +34,14 @@ module CodeLister
28
34
  (files_with_extension + files_without_extension).sort
29
35
  end
30
36
 
31
- # Filter out the list based on given list of words
37
+ # Filter out the list based on simple criteria
38
+ #
39
+ # @param [Array<String>] file_list the input file list
40
+ # @param [Hash<Symbol, Object>] args the option hash
41
+ # @option args [Array<String>] :inc_words list of words that must be match to be included in the result
42
+ # @option args [Array<String>] :exc_words list of words that will be excluded fromt the result
43
+ # @option args [Boolean] :ignore_case flag to indicate how the string comparision should be performed
44
+ # @return [Array<String>] the original list with the result filtered
32
45
  def filter(file_list, args = {})
33
46
  opts = {
34
47
  inc_words: [],
@@ -3,13 +3,9 @@ module CodeLister
3
3
  class << self
4
4
  def run(options = {})
5
5
  args = default_options.merge(options)
6
-
7
6
  files = CodeLister.files(args)
8
-
9
- # Now filter out the list if any
10
7
  inc_words = args.fetch(:inc_words, [])
11
8
  exc_words = args.fetch(:exc_words, [])
12
-
13
9
  files = CodeLister.filter(files, inc_words: inc_words,
14
10
  exc_words: exc_words)
15
11
  puts files
@@ -19,13 +15,13 @@ module CodeLister
19
15
  private
20
16
 
21
17
  def default_options
22
- {base_dir: Dir.pwd,
23
- recursive: true,
24
- ignore_case: true,
25
- inc_words: [],
26
- exc_words: [],
27
- exts: [],
28
- non_exts: []}
18
+ { base_dir: Dir.pwd,
19
+ recursive: true,
20
+ ignore_case: true,
21
+ inc_words: [],
22
+ exc_words: [],
23
+ exts: [],
24
+ non_exts: [] }
29
25
  end
30
26
  end
31
27
  end
@@ -1,3 +1,3 @@
1
1
  module CodeLister
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
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.1
4
+ version: 0.1.2
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-05-17 00:00:00.000000000 Z
11
+ date: 2014-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '0.20'
145
+ version: '0.23'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '0.20'
152
+ version: '0.23'
153
153
  description: List/filter files similar to 'find then grep' command in Linux/Unix based
154
154
  system
155
155
  email: