Class: CollectionsFactory
- Inherits:
-
Array
- Object
- Array
- CollectionsFactory
- Defined in:
- lib/test-factory/collections_factory.rb
Overview
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
CollectionsFactory
Use this as the superclass for your data object collection classes.
Direct Known Subclasses
Class Method Summary collapse
-
.contains(klass) ⇒ Object
Defines the class of objects contained in the collection.
Instance Method Summary collapse
-
#copy ⇒ Object
Makes a “deep copy” of the Collection.
-
#initialize(browser) ⇒ CollectionsFactory
constructor
A new instance of CollectionsFactory.
-
#notify_members(*updates) ⇒ Object
Used in conjunction with the Parent object containing the collection.
Constructor Details
#initialize(browser) ⇒ CollectionsFactory
Returns a new instance of CollectionsFactory.
22 23 24 |
# File 'lib/test-factory/collections_factory.rb', line 22 def initialize(browser) @browser=browser end |
Class Method Details
.contains(klass) ⇒ Object
Defines the class of objects contained in the collection
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/test-factory/collections_factory.rb', line 28 def self.contains klass # Creates a method called "add" that will create the specified data # object and then add it as an item in the collection. # # Note that it's assumed that the target data object will have a # create method defined. If not, this will not work properly. define_method 'add' do |opts| element = klass.new @browser, opts element.create self << element end end |
Instance Method Details
#copy ⇒ Object
Makes a “deep copy” of the Collection. See the #data_object_copy method description in the DataObject class for more information.
46 47 48 49 50 51 52 |
# File 'lib/test-factory/collections_factory.rb', line 46 def copy new_collection = self.class.new(@browser) self.each do |item| new_collection << item.data_object_copy end new_collection end |
#notify_members(*updates) ⇒ Object
Used in conjunction with the Parent object containing the collection.
The parent sends updated information to the collection(s) using #notify_collections
60 61 62 |
# File 'lib/test-factory/collections_factory.rb', line 60 def notify_members *updates self.each { |member| member.update_from_parent *updates } end |