Class: ActiveGuide::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/active_guide/base.rb

Overview

This class defines a DSL in order to define guides for various purpose like best pratices

ActiveGuide::Base.new :cap_2016 do
  result :penalty_percentage
  before do
    # Some cool code
    variables.penalty_percentage = 0
  end
  group :animals do
    test :stuff_well_done, -> { Stuff.well_done? }
    question :have_you_done_this_task, before: -> { Task.any? }
    test :other_stuff_done, if: :stuff_well_done do
      validate do
        OtherStuff.done? and ManyOtherStuff.done?
      end
      after do |validated|
        unless validated
          variables.penalty_percentage += 1
        end
      end
    end
  end
end

Class Method Summary collapse

Class Method Details

.import_from(guide) ⇒ Object


38
39
40
41
42
43
44
# File 'lib/active_guide/base.rb', line 38

def import_from(guide)
  if guide.root
    guide.root.items.each do |item|
      @@root.add_item item.dup
    end
  end
end

.inherited(subclass) ⇒ Object


33
34
35
36
# File 'lib/active_guide/base.rb', line 33

def inherited(subclass)
  @@root = Group.new(nil, :root)
  subclass.import_from(self)
end

.run(*args) ⇒ Object

Run an analyses with default SimpleAnalyzer by default


47
48
49
50
51
52
# File 'lib/active_guide/base.rb', line 47

def run(*args)
  options  = args.extract_options!
  analyzer = args.shift || options[:analyzer]
  analyzer ||= SimpleAnalyzer.new
  analyzer.run(self, options)
end