Class: Git::Conform::FileChecker

Inherits:
BaseChecker show all
Defined in:
lib/git/conform/checkers/file_checker.rb

Class Attribute Summary collapse

Attributes inherited from BaseChecker

#filename

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseChecker

#check_conformity, #check_exclusion, #initialize

Constructor Details

This class inherits a constructor from Git::Conform::BaseChecker

Class Attribute Details

.file_exclusion_patternsObject (readonly)

Returns the value of attribute file_exclusion_patterns.



9
10
11
# File 'lib/git/conform/checkers/file_checker.rb', line 9

def file_exclusion_patterns
  @file_exclusion_patterns
end

Class Method Details

.available_checkersObject



42
43
44
45
46
# File 'lib/git/conform/checkers/file_checker.rb', line 42

def self.available_checkers
  @available_checkers.map(&:name).map { |class_name|
    class_name.match(/\AGit::Conform::(.*Checker)\Z/)[1]
  }
end

.excluded?(filename) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/git/conform/checkers/file_checker.rb', line 11

def excluded?(filename)
  file_exclusion_patterns.any? { |pattern|
    File.fnmatch?(pattern, filename)
  }
end

.inherited(subclass) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/git/conform/checkers/file_checker.rb', line 33

def self.inherited(subclass)
  # keep track of all defined subclasses
  # for the "--available" command option
  @available_checkers << subclass
  # ensure all file checkers "inherit" the @file_exclusion_patterns class instance variable
  # http://stackoverflow.com/questions/10728735/inherit-class-level-instance-variables-in-ruby
  subclass.instance_variable_set(:@file_exclusion_patterns, @file_exclusion_patterns.dup)
end

Instance Method Details

#conforms?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/git/conform/checkers/file_checker.rb', line 23

def conforms?
  true
end

#contentObject



27
28
29
# File 'lib/git/conform/checkers/file_checker.rb', line 27

def content
  File.read(@filename)
end

#excluded?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/git/conform/checkers/file_checker.rb', line 19

def excluded?
  self.class.excluded? @filename
end