Class: Uttk::Strategies::Collection
- Includes:
- Abstract
- Defined in:
- lib/uttk/strategies/Collection.rb
Overview
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.
Instance Attribute Summary
Attributes inherited from Strategy
Instance Method Summary collapse
- #attributes(other = nil, &block) ⇒ Object
-
#attributes=(other) ⇒ Object
:nodoc:.
-
#contents=(other) ⇒ Object
:nodoc:.
-
#create(anObject = strategyclass, &block) ⇒ Object
Create a new test, using the current loader, and add it to the collection.
-
#initialize(*a, &b) ⇒ Collection
constructor
A new instance of Collection.
-
#method_missing(key, val = nil, *a) ⇒ Object
:nodoc:.
- #strategyclass ⇒ Object
- #strategyclass=(aClass) ⇒ Object
Methods inherited from Composite
#<<, #contents, #initialize_copy, #initialize_test
Methods inherited from Strategy
#abort, #assign, #clean_instance_variables, #display_unexpected_exc, #display_unexpected_synflow_exc, #fail, #initialize_flow_factory, #name=, #pass, #raise_error, #reject, #run, #running?, #skip, #skip_if_cached, #skip_wrt_rpath_and_rpath_exclude, #strategy, #strategy=, #symbols=, #symtbl, #symtbl=, #testify, #timeout=, to_form, #to_s, to_yaml_type, #wclass=
Constructor Details
#initialize(*a, &b) ⇒ Collection
Returns a new instance of Collection.
20 21 22 23 24 |
# File 'lib/uttk/strategies/Collection.rb', line 20 def initialize ( *a, &b ) @attributes = OHash.new @internal_contents = [] super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key, val = nil, *a) ⇒ Object
:nodoc:
139 140 141 142 143 144 145 146 147 |
# File 'lib/uttk/strategies/Collection.rb', line 139 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 = nil, &block) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# 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 |
#attributes=(other) ⇒ Object
:nodoc:
118 119 120 |
# File 'lib/uttk/strategies/Collection.rb', line 118 def attributes=(other) # :nodoc: other.each { |k,v| @attributes[k] = v } end |
#contents=(other) ⇒ Object
:nodoc:
100 101 102 |
# File 'lib/uttk/strategies/Collection.rb', line 100 def contents= ( other ) # :nodoc: @internal_contents = other end |
#create(anObject = strategyclass, &block) ⇒ Object
Create a new test, using the current loader, and add it to the collection.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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 |
#strategyclass ⇒ Object
128 129 130 |
# File 'lib/uttk/strategies/Collection.rb', line 128 def strategyclass @attributes[:strategy] end |
#strategyclass=(aClass) ⇒ Object
123 124 125 |
# File 'lib/uttk/strategies/Collection.rb', line 123 def strategyclass= ( aClass ) @attributes[:strategy] = aClass end |