class FastIgnore::ShebangRule
Attributes
file_path_pattern[R]
negation[R]
negation?[R]
rule[R]
squashable_type[R]
Public Class Methods
new(rule, negation, file_path_pattern)
click to toggle source
# File lib/fast_ignore/shebang_rule.rb, line 23 def initialize(rule, negation, file_path_pattern) @rule = rule @negation = negation @file_path_pattern = file_path_pattern @squashable_type = (negation ? 13 : 12) + file_path_pattern.object_id freeze end
Public Instance Methods
component_rules_count()
click to toggle source
# File lib/fast_ignore/shebang_rule.rb, line 19 def component_rules_count 1 end
dir_only?()
click to toggle source
# File lib/fast_ignore/shebang_rule.rb, line 37 def dir_only? false end
file_only?()
click to toggle source
# File lib/fast_ignore/shebang_rule.rb, line 33 def file_only? true end
inspect()
click to toggle source
:nocov:
# File lib/fast_ignore/shebang_rule.rb, line 42 def inspect allow_fragment = 'allow ' if @negation in_fragment = " in #{@file_path_pattern}" if @file_path_pattern "#<ShebangRule #{allow_fragment}#!:#{@rule.to_s[15..-4]}#{in_fragment}>" end
match?(relative_path, full_path, filename, content)
click to toggle source
:nocov:
# File lib/fast_ignore/shebang_rule.rb, line 49 def match?(relative_path, full_path, filename, content) return false if filename.include?('.') return false unless (not @file_path_pattern) || @file_path_pattern.match?(relative_path) (content || first_line(full_path))&.match?(@rule) end
shebang?()
click to toggle source
# File lib/fast_ignore/shebang_rule.rb, line 56 def shebang? true end
squash(rules)
click to toggle source
# File lib/fast_ignore/shebang_rule.rb, line 15 def squash(rules) ::FastIgnore::ShebangRule.new(::Regexp.union(rules.map(&:rule)).freeze, negation?, file_path_pattern) end
Private Instance Methods
first_line(path)
click to toggle source
# File lib/fast_ignore/shebang_rule.rb, line 62 def first_line(path) # rubocop:disable Metrics/MethodLength file = ::File.new(path) first_line = new_fragment = file.sysread(64) if first_line.start_with?('#!') until new_fragment.include?("\n") new_fragment = file.sysread(64) first_line += new_fragment end else file.close return end file.close first_line rescue ::EOFError, ::SystemCallError # :nocov: file&.close # :nocov: first_line end