Module: Panache
- Defined in:
- lib/panache.rb,
lib/panache/version.rb
Defined Under Namespace
Classes: Printer, Rule, Style, Violation
Constant Summary collapse
- DEFAULT_TAB_SPACES =
2
- DEFAULT_STYLE_PATH =
File.("~/repos/panache/panache_styles")
- VERSION =
"0.1.3"
- @@styles =
[]
Class Method Summary collapse
- .add_style(style) ⇒ Object
-
.check_file(path) ⇒ Object
Check a given file against loaded styles.
-
.check_path(path) ⇒ Object
Check a file or directory.
-
.load_styles(directory = DEFAULT_STYLE_PATH) ⇒ Object
Load all Panache styles (files matching *_style.rb) from a given directory.
Class Method Details
.add_style(style) ⇒ Object
76 77 78 |
# File 'lib/panache.rb', line 76 def self.add_style(style) @@styles << style end |
.check_file(path) ⇒ Object
Check a given file against loaded styles.
93 94 95 96 97 98 99 100 |
# File 'lib/panache.rb', line 93 def self.check_file(path) styles = @@styles.select { |style| style.checks? path } line_number = 0 File.open(path).each_with_index.flat_map do |line, line_number| line_number += 1 styles.flat_map { |style| style.check(line) }.each { |violation| violation.line_number = line_number } end end |
.check_path(path) ⇒ Object
Check a file or directory
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/panache.rb', line 103 def self.check_path(path) if File.directory? path files = Find.find(path).select { |sub_path| File.file? sub_path } elsif File.file? path files = [path] else puts "Skipping path: #{path}".yellow return {} end puts "Checking #{path}".green results = {} files.each { |file| results[file] = Panache.check_file file } results end |
.load_styles(directory = DEFAULT_STYLE_PATH) ⇒ Object
Load all Panache styles (files matching *_style.rb) from a given directory.
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/panache.rb', line 81 def self.load_styles(directory = DEFAULT_STYLE_PATH) raise "Need a directory of Panache styles" unless File.directory?(directory) style_files = Dir.glob(File.join(directory, "*_style.rb")) raise "No Panache styles found in #{directory}" if style_files.empty? style_files.each do |style| puts "Loading #{style}...".green load style end puts "Loaded #{style_files.size} style#{"s" if style_files.size != 1}.".green end |