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. '../../rules.d', File.dirname(__FILE__)
- SYNTAXES =
[:css, :html, :js]
Constants included from Helper::Logger
Class Method Summary collapse
- .add(syntax, scope, opt) ⇒ Object
- .all ⇒ Object (also: rules)
- .import ⇒ Object
-
.validations_for_file(opt = {}) ⇒ Object
(also: for_file)
Public: Rules for file validation.
Methods included from Helper::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 |
.all ⇒ Object Also known as: rules
42 43 44 45 46 |
# File 'lib/fdlint/rule.rb', line 42 def all @rules ||= {} import unless @imported @rules end |
.import ⇒ Object
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 |