class FactoryTrace::Structures::Collection
Attributes
factories[R]
traits[R]
Public Class Methods
new(factories = [], traits = [])
click to toggle source
@param [Array<String, FactoryTrace::Structures::Factory>] @param [Array<String, FactoryTrace::Structures::Trait>]
# File lib/factory_trace/structures/collection.rb, line 8 def initialize(factories = [], traits = []) @factories = factories @traits = traits end
Public Instance Methods
==(collection)
click to toggle source
@return [Boolean]
# File lib/factory_trace/structures/collection.rb, line 72 def ==(collection) return false unless collection.is_a?(FactoryTrace::Structures::Collection) factories == collection.factories && traits == collection.traits end
add(element)
click to toggle source
@param [FactoryTrace::Structures::Factory|FactoryTrace::Structures::Trait] element
@return [FactoryTrace::Structures::Factory|FactoryTrace::Structures::Trait]
# File lib/factory_trace/structures/collection.rb, line 16 def add(element) case element when FactoryTrace::Structures::Factory then factories << element when FactoryTrace::Structures::Trait then traits << element end element end
find_factory_by_names(names)
click to toggle source
@param [Array<String>] names
@return [FactoryTrace::Structures::Factory|nil]
# File lib/factory_trace/structures/collection.rb, line 28 def find_factory_by_names(names) factories.find { |factory| (names & factory.names).size > 0 } end
find_trait_by_name(name)
click to toggle source
@param [String] name
@return [FactoryTrace::Structures::Trait|nil]
# File lib/factory_trace/structures/collection.rb, line 35 def find_trait_by_name(name) traits.find { |trait| name == trait.name } end
merge!(collection)
click to toggle source
Merge passed collection into self
@param [FactoryTrace::Structures::Collection]
# File lib/factory_trace/structures/collection.rb, line 50 def merge!(collection) collection.factories.each do |factory| if (persisted = find_factory_by_names(factory.names)) persisted.merge!(factory) else add(factory) end end collection.traits.each do |trait| add(trait) unless find_trait_by_name(trait.name) end end
to_h()
click to toggle source
@return [Hash]
# File lib/factory_trace/structures/collection.rb, line 40 def to_h { factories: factories.map(&:to_h), traits: traits.map(&:to_h) } end
total()
click to toggle source
Total number of factories and traits
@return [Integer]
# File lib/factory_trace/structures/collection.rb, line 67 def total traits.size + factories.size + factories.sum { |factory| factory.traits.size } end