Module: Wizardry::Base::ClassMethods

Defined in:
lib/wizardry/base.rb

Instance Method Summary collapse

Instance Method Details

#wizardry(*steps) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/wizardry/base.rb', line 6

def wizardry(*steps)
  class_attribute :steps, :steps_regexp, instance_writer: false

  self.steps = steps.map{ |s| s.to_s.inquiry }
  self.steps_regexp = Regexp.new(steps.join('|'))

  include WizardryMethods

  [*Wizardry::ORDINALS.first(steps.size - 1), :last].each do |method|
    class_eval <<-EOT, __FILE__, __LINE__ + 1
      def #{method}_step                # def first_step
        steps.#{method}                 #   steps.first
      end                               # end

      def #{method}_step?               # def first_step?
        current_step == #{method}_step  #   current_step == first_step
      end                               # end
    EOT
  end
end