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.
614
615
616
617
618
|
# File 'lib/command-set/results.rb', line 614
def initialize(io)
super(io)
@strategies = self.class.strategy_set(self)
@strategy_stack = [@strategies[:default]]
end
|
Class Method Details
.inherited(sub) ⇒ Object
594
595
596
597
598
599
600
601
602
603
|
# File 'lib/command-set/results.rb', line 594
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
590
591
592
|
# File 'lib/command-set/results.rb', line 590
def strategy(name, base_klass = FormatStrategy, &def_block)
@strategies[name.to_sym] = Class.new(base_klass, &def_block)
end
|
.strategy_set(formatter) ⇒ Object
605
606
607
608
609
610
611
|
# File 'lib/command-set/results.rb', line 605
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
623
624
625
|
# File 'lib/command-set/results.rb', line 623
def current_strategy
@strategy_stack.last
end
|
#pop_strategy(name) ⇒ Object
633
634
635
636
637
|
# File 'lib/command-set/results.rb', line 633
def pop_strategy(name)
if current_strategy.name == name
@strategy_stack.pop
end
end
|
#push_strategy(name) ⇒ Object
627
628
629
630
631
|
# File 'lib/command-set/results.rb', line 627
def push_strategy(name)
if @strategies.has_key?(name)
@strategy_stack.push(@strategies[name])
end
end
|