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)


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

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.



8
9
10
# File 'lib/factory_trace/structures/factory.rb', line 8

def declaration_names
  @declaration_names
end

#definition_pathObject (readonly)

Returns the value of attribute definition_path.



8
9
10
# File 'lib/factory_trace/structures/factory.rb', line 8

def definition_path
  @definition_path
end

#namesObject (readonly)

Returns the value of attribute names.



8
9
10
# File 'lib/factory_trace/structures/factory.rb', line 8

def names
  @names
end

#parent_nameObject (readonly)

Returns the value of attribute parent_name.



8
9
10
# File 'lib/factory_trace/structures/factory.rb', line 8

def parent_name
  @parent_name
end

#traitsObject (readonly)

Returns the value of attribute traits.



8
9
10
# File 'lib/factory_trace/structures/factory.rb', line 8

def traits
  @traits
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

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

#merge!(factory) ⇒ Object

Merge passed factory into self



37
38
39
40
41
# File 'lib/factory_trace/structures/factory.rb', line 37

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>)


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

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