Module: Banalize
- Defined in:
- lib/banalize.rb,
lib/banalize/files.rb,
lib/banalize/errors.rb,
lib/banalize/parser.rb,
lib/banalize/runner.rb,
lib/banalize/policy.rb,
lib/helpers/beautify.rb,
lib/banalize/registry.rb,
lib/banalize/exception.rb,
lib/helpers/description.rb,
lib/banalize/parser/numbered.rb,
lib/banalize/policy/severity.rb,
lib/banalize/parser/variables.rb,
lib/banalize/parser/pod_comments.rb
Overview
This is shamelessly stolen form Rspec::DSL. Inject method policy
into the top level namespace, so the we can use in policy definition
without need to define class inheritance.
Registerd policies are listed in @@policies
array.
Defined Under Namespace
Modules: DSL Classes: BanalizeError, Describe, Errors, Files, Numbered, Parser, Policy, Registry, Runner
Constant Summary
- ROOT =
File.dirname(File.dirname(__FILE__))
- VERSION =
File.read(ROOT+'/version.txt').chomp.strip
- USER =
{ dot_banalize: dot_banalize, config: "#{dot_banalize}/config", # Default user config file styles: "#{dot_banalize}/style", # Default style file policies: "#{dot_banalize}/policies" }
- TRUNCATE =
Truncate long error lines
ENV["BANALIZE_TRUNCATE_LINES"] == 'false' ? nil : 60
Class Method Summary (collapse)
-
+ (Object) beautify(hash, indent = ' ')
Make ouput text indented and apply colors to it if this is required.
-
+ (Array of Hashes) run(bash, search)
Run policy check and return result of it.
Class Method Details
+ (Object) beautify(hash, indent = ' ')
Make ouput text indented and apply colors to it if this is required
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/helpers/beautify.rb', line 8 def self.beautify hash, indent=' ' out = '' l1 = "\n"+indent l2 = "\n" << indent*2 l3 = "\n" << indent*2 << "## " hash.each do |file,results| out << "\n\n#{file.color(:file)}" results.each do |f_or_s, checks| out << l1 << f_or_s << l1 << '-'*10 checks.each do |policy, string| out << l1 << policy.to_s.color(f_or_s == 'Fail' ? :red : :yellow) if string lines = case string when String string.split("\n") when Array string end lines.each do |line| line.gsub!(/(line \d+:)(.*)/, '\1' +"#{l3} "+ '\2' ) out << l3 << line end end end end end out end |
+ (Array of Hashes) run(bash, search)
Run policy check and return result of it.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/banalize/runner.rb', line 15 def self.run bash, search $current = bash run_list = Policy.search search if run_list.empty? raise Banalize::Runner::Error, "No policy satisfying criteria: #{search.inspect}" end res = { } run_list.each do |policy| res[policy[:policy]] = Banalize::Runner.new(bash, policy).result end res end |