Module: Fdlint::Rule

Extended by:
Helper::Logger
Defined in:
lib/fdlint/rule.rb,
lib/fdlint/rule/dsl.rb,
lib/fdlint/rule/validation.rb

Defined Under Namespace

Modules: DSL Classes: Validation

Constant Summary collapse

RULE_PATH =
File.expand_path '../../rules.d', File.dirname(__FILE__)
SYNTAXES =
[:css, :html, :js]

Constants included from Helper::Logger

Helper::Logger::LEVELS

Class Method Summary collapse

Methods included from Helper::Logger

log, logger

Class Method Details

.add(syntax, scope, opt) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/fdlint/rule.rb', line 66

def add( syntax, scope, opt )
  debug { "  -> adding rule: #{syntax.inspect} - #{scope.inspect} - #{opt[:desc]}" }
  cache = @rules[syntax] ||= []
  cache << Validation.new( scope, opt[:block] ).tap do |v|
    v.desc = opt[:desc]
    v.uri  = opt[:uri]
  end
  @rules
end

.allObject Also known as: rules



42
43
44
45
46
# File 'lib/fdlint/rule.rb', line 42

def all
  @rules ||= {}
  import unless @imported
  @rules
end

.importObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fdlint/rule.rb', line 50

def import
  debug { "importing rules" }
  Dir.glob( File.join RULE_PATH, '**', '*.rule.rb' ) do |rule|
    begin
      DSL.instance_eval File.read(rule), rule
    rescue SyntaxError, NoMethodError => e
      fatal { "Error parsing rule file:".red }
      fatal { "  -> #{rule}" }
      fatal { "" }
      raise
    end
  end
  @imported = true
  debug { "done" }
end

.validations_for_file(opt = {}) ⇒ Object Also known as: for_file

Public: Rules for file validation

opt - options including syntax

Returns an Array holding all validations for this file



21
22
23
24
25
# File 'lib/fdlint/rule.rb', line 21

def validations_for_file( opt={} )
  (all[opt[:syntax]] || []).select do |validation|
    validation.scope == :file
  end
end