Class: Command::Results::StrategyFormatter
Defined Under Namespace
Classes: FormatStrategy
Instance Attribute Summary
Attributes inherited from Formatter
#advice
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Formatter
#apply_advice, #closed_begin_list, #closed_end_list, #closed_item, #default_advice, #finish, #notify, #receive_advice, #saw_begin_list, #saw_end_list, #saw_item, #start
Constructor Details
Returns a new instance of StrategyFormatter.
619
620
621
622
623
|
# File 'lib/command-set/results.rb', line 619
def initialize(io)
super(io)
@strategies = self.class.strategy_set(self)
@strategy_stack = [@strategies[:default]]
end
|
Class Method Details
.inherited(sub) ⇒ Object
599
600
601
602
603
604
605
606
607
608
|
# File 'lib/command-set/results.rb', line 599
def inherited(sub)
self.instance_variables.each do |var|
value = self.instance_variable_get(var)
if value.nil?
sub.instance_variable_set(var, nil)
else
sub.instance_variable_set(var, value.dup)
end
end
end
|
.strategy(name, base_klass = FormatStrategy, &def_block) ⇒ Object
595
596
597
|
# File 'lib/command-set/results.rb', line 595
def strategy(name, base_klass = FormatStrategy, &def_block)
@strategies[name.to_sym] = Class.new(base_klass, &def_block)
end
|
.strategy_set(formatter) ⇒ Object
610
611
612
613
614
615
616
|
# File 'lib/command-set/results.rb', line 610
def strategy_set(formatter)
set = {}
@strategies.each_pair do |name, klass|
set[name] = klass.new(name, formatter)
end
return set
end
|
Instance Method Details
#current_strategy ⇒ Object
628
629
630
|
# File 'lib/command-set/results.rb', line 628
def current_strategy
@strategy_stack.last
end
|
#pop_strategy(name) ⇒ Object
638
639
640
641
642
|
# File 'lib/command-set/results.rb', line 638
def pop_strategy(name)
if current_strategy.name == name
@strategy_stack.pop
end
end
|
#push_strategy(name) ⇒ Object
632
633
634
635
636
|
# File 'lib/command-set/results.rb', line 632
def push_strategy(name)
if @strategies.has_key?(name)
@strategy_stack.push(@strategies[name])
end
end
|