Module: Foobara::CommandPatternImplementation::Concerns::Entities::ClassMethods

Defined in:
foobara-0.6.1/projects/entities_plumbing/src/extensions/command_pattern_implementation/concerns/entities.rb

Instance Method Summary collapse

Instance Method Details

#depends_on_entities(*entities_to_add) ⇒ Object

Only needed for entities not discoverable through the inputs



21
22
23
24
25
26
27
28
29
# File 'projects/entities_plumbing/src/extensions/command_pattern_implementation/concerns/entities.rb', line 21

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



31
32
33
# File 'projects/entities_plumbing/src/extensions/command_pattern_implementation/concerns/entities.rb', line 31

def depends_on_entity(entity_class)
  depends_on_entities << entity_class
end

#entity_class_pathsObject



35
36
37
38
39
# File 'projects/entities_plumbing/src/extensions/command_pattern_implementation/concerns/entities.rb', line 35

def entity_class_paths
  @entity_class_paths ||= Entity.construct_associations(
    inputs_type
  ).transform_values(&:target_class)
end

#inputsObject



8
9
10
11
12
13
14
15
16
17
18
# File 'projects/entities_plumbing/src/extensions/command_pattern_implementation/concerns/entities.rb', line 8

def inputs(...)
  if defined?(@entity_class_paths)
    remove_instance_variable(:@entity_class_paths)
  end

  if defined?(@inputs_association_paths)
    remove_instance_variable(:@inputs_association_paths)
  end

  super
end

#load_allObject



57
58
59
# File 'projects/entities_plumbing/src/extensions/command_pattern_implementation/concerns/entities.rb', line 57

def load_all
  to_load(*entity_class_paths.keys)
end

#to_load(*paths) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'projects/entities_plumbing/src/extensions/command_pattern_implementation/concerns/entities.rb', line 41

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_input_error(path, 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_classesObject



61
62
63
# File 'projects/entities_plumbing/src/extensions/command_pattern_implementation/concerns/entities.rb', line 61

def to_load_paths_and_error_classes
  @to_load_paths_and_error_classes
end