| Class | Uttk::Strategies::Collection |
| In: |
lib/uttk/strategies/Collection.rb
|
| Parent: | Composite |
I do the same job as the Composite strategy, plus I provide the attributes attribute which allow to share common attributes of the strategies I compose.
| internal_contents | [R] |
# File lib/uttk/strategies/Collection.rb, line 20 def initialize ( *a, &b ) @attributes = OHash.new @internal_contents = [] super end
# File lib/uttk/strategies/Collection.rb, line 105 def attributes(other=nil, &block) if other.nil? if block.nil? @attributes else self.attributes = HashEval.new(&block).hash end else self.attributes = other end end
Create a new test, using the current loader, and add it to the collection.
# File lib/uttk/strategies/Collection.rb, line 29 def create ( anObject=strategyclass, &block ) super do |t| # @log.debug{"assign collection attributes #{@attributes.size}"} @attributes.each do |k,v| # @log.debug{"assign attribute: #{k}"} next if k == :contents t.assign_one(k, v, true) end if @attributes.has_key? :contents t.assign_one(:contents, @attributes[:contents], true) end block[t] if block @attributes.each do |k,v| t.reject k if t.respond_to? k and t.send(k) == v end end end
# File lib/uttk/strategies/Collection.rb, line 123 def strategyclass= ( aClass ) @attributes[:strategy] = aClass end
# File lib/uttk/strategies/Collection.rb, line 48 def prologue super # Create sub tests if @internal_contents.is_a? Hash unless @internal_contents.ordered? raise ArgumentError, 'hash not ordered' end @internal_contents.each do |name, doc| if doc.is_a? Hash internal_create(doc, name) else create(doc) end end elsif @internal_contents.is_a? Array @internal_contents.each do |doc| if doc.is_a? Hash if doc.size == 1 and (tab = doc.to_a[0])[1].is_a? Hash internal_create(tab[1], tab[0]) else internal_create(doc) end elsif doc.is_a? String internal_create(:name => doc) else create(doc) end end else raise_error 'bad contents type' end # Dump the attributes attr = @attributes.dup.delete_if do |k,v| v.nil? or v.respond_to?(:hidden) or k == :aliases end unless attr.empty? @log.new_node :attributes do attr.each { |k, v| @log[k] = v } end end end