Class: FastIgnore::ShebangRule

Inherits:
Object
  • Object
show all
Defined in:
lib/fast_ignore/shebang_rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rule, negation) ⇒ ShebangRule

Returns a new instance of ShebangRule.



14
15
16
17
18
19
20
21
22
# File 'lib/fast_ignore/shebang_rule.rb', line 14

def initialize(rule, negation)
  @rule = rule
  @negation = negation

  @type = 2
  @type += 1 if negation

  freeze
end

Instance Attribute Details

#negationObject (readonly) Also known as: negation?

Returns the value of attribute negation.



5
6
7
# File 'lib/fast_ignore/shebang_rule.rb', line 5

def negation
  @negation
end

#ruleObject (readonly) Also known as: shebang

Returns the value of attribute rule.



9
10
11
# File 'lib/fast_ignore/shebang_rule.rb', line 9

def rule
  @rule
end

#typeObject (readonly)

Returns the value of attribute type.



12
13
14
# File 'lib/fast_ignore/shebang_rule.rb', line 12

def type
  @type
end

Instance Method Details

#dir_only?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/fast_ignore/shebang_rule.rb', line 28

def dir_only?
  false
end

#file_only?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/fast_ignore/shebang_rule.rb', line 24

def file_only?
  true
end

#inspectObject

:nocov:



37
38
39
# File 'lib/fast_ignore/shebang_rule.rb', line 37

def inspect
  "#<ShebangRule #{'allow ' if @negation}#!:#{@rule.to_s[15..-4]}>"
end

#match?(_, full_path, filename, content) ⇒ Boolean

:nocov:

Returns:

  • (Boolean)


42
43
44
45
46
# File 'lib/fast_ignore/shebang_rule.rb', line 42

def match?(_, full_path, filename, content)
  return false if filename.include?('.')

  (content || first_line(full_path))&.match?(@rule)
end

#unanchored?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/fast_ignore/shebang_rule.rb', line 32

def unanchored?
  true
end