Exception: Foobara::Entity::NotFoundError

Inherits:
RuntimeError show all
Defined in:
foobara-0.0.110/projects/entity/src/not_found_error.rb

Instance Attribute Summary

Attributes inherited from Foobara::Error

#backtrace_when_initialized, #backtrace_when_raised, #context, #error_key, #is_fatal, #message

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RuntimeError

category, fatal?, #initialize

Methods inherited from Foobara::Error

#==, abstract, abstract?, category, context, #eql?, fatal?, #fatal?, foobara_manifest, #initialize, #key, message, path, #prepend_path!, runtime_path, symbol, to_h, #to_h, types_depended_on

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Constructor Details

This class inherits a constructor from Foobara::RuntimeError

Class Method Details

.data_pathObject



45
46
47
# File 'foobara-0.0.110/projects/entity/src/not_found_error.rb', line 45

def data_path
  nil
end

.for(criteria, entity_class: self.entity_class, data_path: self.data_path || "") ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'foobara-0.0.110/projects/entity/src/not_found_error.rb', line 34

def for(criteria, entity_class: self.entity_class, data_path: self.data_path || "")
  message = "Could not find #{entity_class} for #{criteria}"
  context = {
    entity_class: entity_class.full_entity_name,
    criteria:,
    data_path: data_path.to_s
  }

  new(context:, message:)
end

.not_found_error_class_name(data_path) ⇒ Object



5
6
7
8
# File 'foobara-0.0.110/projects/entity/src/not_found_error.rb', line 5

def not_found_error_class_name(data_path)
  error_class_name = data_path.path.map { |part| part == :"#" ? "Collection" : Util.classify(part) }.join
  "#{error_class_name}NotFoundError"
end

.subclass(mod, entity_class, data_path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'foobara-0.0.110/projects/entity/src/not_found_error.rb', line 10

def subclass(mod, entity_class, data_path)
  error_class_name = not_found_error_class_name(data_path)

  # TODO: how would we avoid name collisions here??
  Util.make_class("#{mod.name}::#{error_class_name}", self) do
    # TODO: use Concern to change these into attr_accessor instead
    singleton_class.define_method :data_path do
      data_path
    end

    singleton_class.define_method :entity_class do
      entity_class
    end

    singleton_class.define_method :context_type_declaration do
      {
        entity_class: :string, # TODO: we don't have a way to specify an exact value for a type
        criteria: :duck, # TODO: find_by attributes unioned with primary key
        data_path: :string # TODO: we don't have a way to specify an exact value for a type
      }
    end
  end
end

Instance Method Details

#criteriaObject



58
59
60
# File 'foobara-0.0.110/projects/entity/src/not_found_error.rb', line 58

def criteria
  context[:criteria]
end

#data_pathObject



62
63
64
# File 'foobara-0.0.110/projects/entity/src/not_found_error.rb', line 62

def data_path
  context[:data_path]
end

#entity_classObject



66
67
68
# File 'foobara-0.0.110/projects/entity/src/not_found_error.rb', line 66

def entity_class
  context[:entity_class]
end