file_scan 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 30637764091ba4b39b8dc3ead21eb5e14963513083cb842641c1d0c79203c508
4
+ data.tar.gz: b1d5410407ef9ad147bae99ad9d897648ecfdbde52f9bb169c51585b07b74f01
5
+ SHA512:
6
+ metadata.gz: d5d56dc43aff5bb568f747644061907fe0d261364bbed3048ca0b320899644b6d787fef0569b4675dcc813c4f1e0866668ceef2dc3d480a2f1f90205c7b0ff8b
7
+ data.tar.gz: 8c8dec2d713a17ea85d1fc3414f46735dede1f5a6d9cd7f5dd7ebda675ae9558f2206b8395e3a1000f49ebfa687a277bd4021155b6dd4a284a7eac123505544d
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in file_scanner.gemspec
6
+ gemspec
7
+
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ file_scan (0.1.0)
5
+ colorize (~> 0.8.1)
6
+ rake (~> 13.0)
7
+ rubocop (~> 1.7)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ ast (2.4.2)
13
+ colorize (0.8.1)
14
+ parallel (1.20.1)
15
+ parser (3.0.2.0)
16
+ ast (~> 2.4.1)
17
+ rainbow (3.0.0)
18
+ rake (13.0.6)
19
+ regexp_parser (2.1.1)
20
+ rexml (3.2.5)
21
+ rubocop (1.18.4)
22
+ parallel (~> 1.10)
23
+ parser (>= 3.0.0.0)
24
+ rainbow (>= 2.2.2, < 4.0)
25
+ regexp_parser (>= 1.8, < 3.0)
26
+ rexml
27
+ rubocop-ast (>= 1.8.0, < 2.0)
28
+ ruby-progressbar (~> 1.7)
29
+ unicode-display_width (>= 1.4.0, < 3.0)
30
+ rubocop-ast (1.9.0)
31
+ parser (>= 3.0.1.1)
32
+ ruby-progressbar (1.11.0)
33
+ unicode-display_width (2.0.0)
34
+
35
+ PLATFORMS
36
+ x86_64-darwin-20
37
+
38
+ DEPENDENCIES
39
+ file_scan!
40
+
41
+ BUNDLED WITH
42
+ 2.2.27
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 anujchandra
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ require "rubocop/rake_task"
6
+
7
+ RuboCop::RakeTask.new
8
+
9
+ task default: %i[rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "file_scanner"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FileScanner
4
+ # Create a scanner client
5
+ #
6
+ # @author c477y
7
+ class Client
8
+ #
9
+ # Create a new Scanner
10
+ #
11
+ # @param [String] dir Directory to be processed
12
+ # @param [Hash] options
13
+ # @option options [Boolean] :nested Specify if nested directories should be scanned
14
+ # @option options [String] extension Extension of filenames to be selected. Defaults to "*.mp4"
15
+ def initialize(dir, **options)
16
+ @nested = options[:nested]
17
+ @extension = options[:extension].nil? ? "*.mp4" : options[:extension]
18
+ @dir = dir
19
+ end
20
+
21
+ # @param [Proc] block Block of code to be executed for each file
22
+ def each(&block)
23
+ @block = block
24
+ process_directory(@dir)
25
+ end
26
+
27
+ private
28
+
29
+ #
30
+ # Executes a block of code for all files in a given directory. Will scan files
31
+ # in sub-directories if @nested is passed as true
32
+ #
33
+ # @param [String] dir Directory path to scan
34
+ def process_directory(dir)
35
+ Dir.chdir(dir) do
36
+ # Process files in a given directory
37
+ print "Scanning files in #{Dir.pwd}\n".colorize(:blue)
38
+
39
+ Dir.glob(@extension).sort.each { |file| @block.call(file) }
40
+
41
+ # Return unless we want to scan the directories inside
42
+ # the directory `dir`
43
+ return unless @nested
44
+
45
+ nested_dir = Dir["*"].select { |o| File.directory?(o) }
46
+ nested_dir.sort.each do |each|
47
+ process_directory(each)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FileScanner
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "colorize"
4
+ require_relative "file_scanner/client"
5
+ require_relative "file_scanner/version"
6
+
7
+ module FileScanner # :nodoc:
8
+ # @param [String] dir Directory to be processed
9
+ # @param [Hash] options
10
+ # @option options [Boolean] :nested Specify if nested directories should be scanned
11
+ # @option options [String] extension Extension of filenames to be selected. Defaults to "*.mp4"
12
+ def self.new(dir, **options)
13
+ Client.new(dir, **options)
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: file_scan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - c477y
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-09-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ description: A utility gem which scan files recursively inside a directory and performs
56
+ actions with each file
57
+ email:
58
+ - c477y@pm.me
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".rubocop.yml"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE.txt
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - lib/file_scanner.rb
71
+ - lib/file_scanner/client.rb
72
+ - lib/file_scanner/version.rb
73
+ homepage: https://github.com/c477y/file_scanner
74
+ licenses:
75
+ - MIT
76
+ metadata:
77
+ homepage_uri: https://github.com/c477y/file_scanner
78
+ source_code_uri: https://github.com/c477y/file_scanner
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 2.4.0
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubygems_version: 3.2.22
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: A utility gem which scan files recursively inside a directory and performs
98
+ actions with each file
99
+ test_files: []