Class: Satisfactory::Root
- Inherits:
-
Object
- Object
- Satisfactory::Root
- Defined in:
- lib/satisfactory/root.rb
Overview
The root of the factory graph. This is where you begin creating records.
Defined Under Namespace
Classes: FactoryNotDefinedError
Instance Method Summary collapse
-
#add(factory_name, **attributes) ⇒ Object
Add a top-level record to the root.
- #create ⇒ Hash<Symbol, Array<ApplicationRecord>> private
-
#initialize ⇒ Root
constructor
private
A new instance of Root.
- #to_plan ⇒ Hash<Symbol, Array<Hash>> private
- #upstream ⇒ nil private
Constructor Details
#initialize ⇒ Root
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Root.
8 9 10 |
# File 'lib/satisfactory/root.rb', line 8 def initialize @root_records = Hash.new { |h, k| h[k] = [] } end |
Instance Method Details
#add(factory_name, **attributes) ⇒ Object
Add a top-level record to the root. This is your entry point into the factory graph, and the way to begin creating records.
15 16 17 18 19 20 21 22 23 |
# File 'lib/satisfactory/root.rb', line 15 def add(factory_name, **attributes) raise FactoryNotDefinedError, factory_name unless Satisfactory.factory_configurations.key?(factory_name) Satisfactory::Record.new( type: factory_name, upstream: self, attributes:, ).tap { |r| @root_records[factory_name] << r } end |
#create ⇒ Hash<Symbol, Array<ApplicationRecord>>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 30 31 |
# File 'lib/satisfactory/root.rb', line 27 def create @root_records.transform_values do |records| records.map(&:create_self) end end |
#to_plan ⇒ Hash<Symbol, Array<Hash>>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 38 39 |
# File 'lib/satisfactory/root.rb', line 35 def to_plan @root_records.transform_values do |records| records.map(&:build_plan) end end |
#upstream ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
43 44 45 |
# File 'lib/satisfactory/root.rb', line 43 def upstream nil end |