Class: CodeManifest::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/code_manifest/rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ Rule

Returns a new instance of Rule.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/code_manifest/rule.rb', line 7

def initialize(pattern)
  @exclude = false
  @glob = pattern

  if glob.start_with?("!")
    @exclude = true
    @glob = glob.delete_prefix("!")
  end

  if File.absolute_path?(glob)
    @glob = glob.delete_prefix(File::SEPARATOR)
  else
    @glob = File.join("**", glob)
  end
end

Instance Attribute Details

#excludeObject (readonly)

Returns the value of attribute exclude.



5
6
7
# File 'lib/code_manifest/rule.rb', line 5

def exclude
  @exclude
end

#globObject (readonly)

Returns the value of attribute glob.



5
6
7
# File 'lib/code_manifest/rule.rb', line 5

def glob
  @glob
end

Instance Method Details

#match?(file) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
# File 'lib/code_manifest/rule.rb', line 23

def match?(file)
  if File.absolute_path?(file)
    prefix = File.join(CodeManifest.root, "/")
    file = file.delete_prefix(prefix)
  end

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