Class: FactoryTrace::Structures::Factory

Inherits:
Object
  • Object
show all
Includes:
Helpers::Statusable
Defined in:
lib/factory_trace/structures/factory.rb

Constant Summary

Constants included from Helpers::Statusable

Helpers::Statusable::PRIORITY_ORDER

Instance Attribute Summary collapse

Attributes included from Helpers::Statusable

#status

Instance Method Summary collapse

Methods included from Helpers::Statusable

#has_prioritized_status?

Constructor Details

#initialize(names, traits, parent_name: nil, declaration_names: [], definition_path: nil) ⇒ Factory

Returns a new instance of Factory.

Parameters:

  • names (Array<String>)
  • traits (Array<FactoryTrace::Structure::Trait>)
  • parent_name (String|nil) (defaults to: nil)
  • declaration_names (Array<String>) (defaults to: [])
  • definition_path (String) (defaults to: nil)


13
14
15
16
17
18
19
# File 'lib/factory_trace/structures/factory.rb', line 13

def initialize(names, traits, parent_name: nil, declaration_names: [], definition_path: nil)
  @names = names
  @traits = traits
  @parent_name = parent_name
  @declaration_names = declaration_names
  @definition_path = definition_path
end

Instance Attribute Details

#declaration_namesObject (readonly)

Returns the value of attribute declaration_names.



6
7
8
# File 'lib/factory_trace/structures/factory.rb', line 6

def declaration_names
  @declaration_names
end

#definition_pathObject (readonly)

Returns the value of attribute definition_path.



6
7
8
# File 'lib/factory_trace/structures/factory.rb', line 6

def definition_path
  @definition_path
end

#namesObject (readonly)

Returns the value of attribute names.



6
7
8
# File 'lib/factory_trace/structures/factory.rb', line 6

def names
  @names
end

#parent_nameObject (readonly)

Returns the value of attribute parent_name.



6
7
8
# File 'lib/factory_trace/structures/factory.rb', line 6

def parent_name
  @parent_name
end

#traitsObject (readonly)

Returns the value of attribute traits.



6
7
8
# File 'lib/factory_trace/structures/factory.rb', line 6

def traits
  @traits
end

Instance Method Details

#==(factory) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
# File 'lib/factory_trace/structures/factory.rb', line 42

def ==(factory)
  return false unless factory.is_a?(FactoryTrace::Structures::Factory)

  names == factory.names &&
    traits == factory.traits &&
    parent_name == factory.parent_name &&
    declaration_names == factory.declaration_names &&
    definition_path == factory.definition_path
end

#merge!(factory) ⇒ Object

Merge passed factory into self



35
36
37
38
39
# File 'lib/factory_trace/structures/factory.rb', line 35

def merge!(factory)
  factory.traits.each do |trait|
    traits << trait unless traits.any? { |t| t.name == trait.name }
  end
end

#to_hHash<Symbol, Object>

Returns:

  • (Hash<Symbol, Object>)


22
23
24
25
26
27
28
29
30
# File 'lib/factory_trace/structures/factory.rb', line 22

def to_h
  {
    names: names,
    traits: traits.map(&:to_h),
    parent_name: parent_name,
    declaration_names: declaration_names,
    definition_path: definition_path
  }
end