Module: Foobara::CommandPatternImplementation::Concerns::Entities::ClassMethods
- Defined in:
- foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/entities.rb
Instance Method Summary collapse
-
#depends_on_entities(*entities_to_add) ⇒ Object
Only needed for entities not discoverable through the inputs.
- #depends_on_entity(entity_class) ⇒ Object
- #entity_class_paths ⇒ Object
- #load_all ⇒ Object
-
#to_load(*paths) ⇒ Object
TODO: move to better concern! TODO: make work with inheritance.
- #to_load_paths_and_error_classes ⇒ Object
Instance Method Details
#depends_on_entities(*entities_to_add) ⇒ Object
Only needed for entities not discoverable through the inputs
9 10 11 12 13 14 15 16 17 |
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/entities.rb', line 9 def depends_on_entities(*entities_to_add) if entities_to_add.empty? @depends_on_entities ||= Set.new else entities_to_add.each do |entity_class| depends_on_entity(entity_class) end end end |
#depends_on_entity(entity_class) ⇒ Object
19 20 21 |
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/entities.rb', line 19 def depends_on_entity(entity_class) depends_on_entities << entity_class end |
#entity_class_paths ⇒ Object
23 24 25 26 27 28 |
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/entities.rb', line 23 def entity_class_paths # TODO: bust this cache when changing inputs_type?? @entity_class_paths ||= Entity.construct_associations( inputs_type ).transform_values(&:target_class) end |
#load_all ⇒ Object
48 49 50 |
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/entities.rb', line 48 def load_all to_load(*entity_class_paths.keys) end |
#to_load(*paths) ⇒ Object
TODO: move to better concern! TODO: make work with inheritance
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/entities.rb', line 32 def to_load(*paths) h = @to_load_paths_and_error_classes || {} paths.each do |path| path = DataPath.new(path) entity_class = entity_class_paths[path.to_s] error_class = Entity::NotFoundError.subclass(self, entity_class, path) h[path.to_s] = error_class possible_error(error_class) end @to_load_paths_and_error_classes = h.sort_by do |path, _error_class| [DataPath.new(path).path.size, path] end.to_h end |
#to_load_paths_and_error_classes ⇒ Object
52 53 54 |
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/entities.rb', line 52 def to_load_paths_and_error_classes @to_load_paths_and_error_classes end |