Skip to content

Commit 4169584

Browse files
committed
Optimize and release 1.6.0
1 parent be8a62a commit 4169584

5 files changed

Lines changed: 19 additions & 19 deletions

File tree

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
code_manifest (1.5.0)
4+
code_manifest (1.6.0)
55

66
GEM
77
remote: https://rubygems.org/

lib/code_manifest/manifest.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ class Manifest
1111

1212
def initialize(patterns)
1313
@rules ||= Array(patterns).map do |pattern|
14-
Rule.new(CodeManifest.root, pattern)
14+
Rule.new(pattern)
1515
end
1616
end
1717

1818
def files
1919
@files ||= begin
20-
inclusion_files = Dir.glob(inclusion_rules.map(&:glob), GLOB_OPTIONS)
20+
inclusion_files = Dir.glob(inclusion_rules.map(&:glob), GLOB_OPTIONS, base: CodeManifest.root)
2121
inclusion_files.delete_if do |file|
2222
exclusion_rules.any? { |rule| rule.match?(file) }
2323
end

lib/code_manifest/rule.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@ module CodeManifest
44
class Rule
55
attr_reader :exclude, :glob
66

7-
def initialize(root, pattern)
8-
@root = root
7+
def initialize(pattern)
98
@exclude = false
10-
@glob = @root
9+
@glob = pattern
1110

12-
if pattern.start_with?('!')
11+
if glob.start_with?("!")
1312
@exclude = true
14-
pattern = pattern[1..-1]
13+
@glob = glob.delete_prefix("!")
1514
end
1615

17-
if pattern.start_with?('/')
18-
pattern = pattern[1..-1]
16+
if File.absolute_path?(glob)
17+
@glob = glob.delete_prefix(File::SEPARATOR)
1918
else
20-
@glob = @glob.join('**')
19+
@glob = File.join("**", glob)
2120
end
22-
23-
@glob = @glob.join(pattern).to_s
2421
end
2522

2623
def match?(file)
27-
file = File.join(@root, file) unless File.absolute_path?(file)
24+
if File.absolute_path?(file)
25+
prefix = File.join(CodeManifest.root, "/")
26+
file = file.delete_prefix(prefix)
27+
end
2828

2929
File.fnmatch?(glob, file, Manifest::GLOB_OPTIONS)
3030
end

lib/code_manifest/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module CodeManifest
4-
VERSION = '1.5.0'
4+
VERSION = '1.6.0'
55
end

spec/lib/code_manifest/rule_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
require 'tmpdir'
77

88
RSpec.describe CodeManifest::Rule do
9-
let(:root) { Pathname.new('tmp/rule_spec').expand_path }
9+
let(:root) { CodeManifest.root }
1010
let(:pattern) { '**/*' }
11-
let(:rule) { described_class.new(root, pattern) }
11+
let(:rule) { described_class.new(pattern) }
1212

1313
describe '#exclude' do
1414
context 'when exclude pattern' do
@@ -31,15 +31,15 @@
3131
let(:pattern) { '/foo' }
3232

3333
it 'returns rooted glob' do
34-
expect(rule.glob).to eq(root.join('foo').to_s)
34+
expect(rule.glob).to eq('foo')
3535
end
3636
end
3737

3838
context 'when pattern is not rooted' do
3939
let(:pattern) { 'foo' }
4040

4141
it 'returns non-rooted glob' do
42-
expect(rule.glob).to eq(root.join('**/foo').to_s)
42+
expect(rule.glob).to eq('**/foo')
4343
end
4444
end
4545
end

0 commit comments

Comments
 (0)