Class: PathList::Matchers::ShebangRegexp

Inherits:
Object
  • Object
show all
Defined in:
lib/path_list/matchers/shebang_regexp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rule, negation) ⇒ ShebangRegexp

Returns a new instance of ShebangRegexp.



9
10
11
12
13
14
15
# File 'lib/path_list/matchers/shebang_regexp.rb', line 9

def initialize(rule, negation)
  @rule = rule
  @return_value = negation ? :allow : :ignore
  @squash_id = negation ? :allow_shebang : :ignore_shebang

  freeze
end

Instance Attribute Details

#ruleObject (readonly)

Returns the value of attribute rule.



7
8
9
# File 'lib/path_list/matchers/shebang_regexp.rb', line 7

def rule
  @rule
end

#squash_idObject (readonly)

Returns the value of attribute squash_id.



6
7
8
# File 'lib/path_list/matchers/shebang_regexp.rb', line 6

def squash_id
  @squash_id
end

Instance Method Details

#dir_only?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/path_list/matchers/shebang_regexp.rb', line 25

def dir_only?
  false
end

#file_only?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/path_list/matchers/shebang_regexp.rb', line 21

def file_only?
  true
end

#inspectObject

:nocov:



30
31
32
# File 'lib/path_list/matchers/shebang_regexp.rb', line 30

def inspect
  "#<ShebangRegexp #{@return_value} /#{@rule.to_s[26..-4]}/>"
end

#match?(candidate) ⇒ Boolean

:nocov:

Returns:

  • (Boolean)


35
36
37
38
39
# File 'lib/path_list/matchers/shebang_regexp.rb', line 35

def match?(candidate)
  return false if candidate.filename.include?('.')

  @return_value if candidate.first_line&.match?(@rule)
end

#shebang?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/path_list/matchers/shebang_regexp.rb', line 41

def shebang?
  true
end

#squash(list) ⇒ Object



17
18
19
# File 'lib/path_list/matchers/shebang_regexp.rb', line 17

def squash(list)
  self.class.new(::Regexp.union(list.map(&:rule)), @return_value == :allow)
end