Class: TTK::Strategies::Collection

Inherits:
Composite show all
Includes:
Abstract
Defined in:
lib/ttk/strategies/Collection.rb

Direct Known Subclasses

Package, Pool, Suite

Instance Attribute Summary

Attributes inherited from Strategy

#status, #symtbl

Instance Method Summary collapse

Methods inherited from Composite

#<<, #initialize_test, #new_symtbl

Methods inherited from Strategy

#abort, #assign, #clean_instance_variables, #display_unexpected_exc, #display_unexpected_synflow_exc, #fail, #initialize_flow_factory, #pass, #raise_error, #reject, #run, #running?, #skip, #skip_if_cached, #strategy, #strategy=, #symbols=, #testify, #timeout=, #to_s, #wclass=

Constructor Details

#initialize(*a, &b) ⇒ Collection

Returns a new instance of Collection.



15
16
17
18
# File 'lib/ttk/strategies/Collection.rb', line 15

def initialize ( *a, &b )
  @attributes = OHash.new
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, val = nil, *a) ⇒ Object

:nodoc:



118
119
120
121
122
123
124
125
126
# File 'lib/ttk/strategies/Collection.rb', line 118

def method_missing(key, val=nil, *a) # :nodoc:
  super unless a.empty?
	key = key.to_s
	if key =~ /^(.*)=$/
	  @attributes[$1] = val
	else
	  @attributes[key]
	end
end

Instance Method Details

#attributes=(other) ⇒ Object

:nodoc:



97
98
99
# File 'lib/ttk/strategies/Collection.rb', line 97

def attributes=(other) # :nodoc:
	other.each { |k,v| @attributes[k] = v }
end

#contents=(other) ⇒ Object

FIXME: Collection should create the tests in its contents during its

prologue as every other Composite do.


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ttk/strategies/Collection.rb', line 67

def contents= ( other ) # :nodoc:
  if other.is_a? Hash
    raise ArgumentError, 'hash not ordered' unless other.ordered?
    other.each do |name, doc|
      if doc.is_a? Hash
        internal_create(doc, name)
      else
        create(doc)
      end
    end
  elsif other.is_a? Array
    other.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 ArgumentError, 'bad contents type'
  end
end

#create(anObject = strategyclass, &block) ⇒ Object

Create a new test, using the current loader, and add it to the collection.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ttk/strategies/Collection.rb', line 23

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_given?
    @attributes.each do |k,v|
      t.reject k if t.respond_to? k and t.send(k) == v
    end
  end
end

#strategyclassObject



107
108
109
# File 'lib/ttk/strategies/Collection.rb', line 107

def strategyclass
  @attributes[:strategy]
end

#strategyclass=(aClass) ⇒ Object



102
103
104
# File 'lib/ttk/strategies/Collection.rb', line 102

def strategyclass= ( aClass )
  @attributes[:strategy] = aClass
end