Class: Foobara::Entity::NotFoundError
- Defined in:
- foobara-0.6.1/projects/entities/projects/entity/src/not_found_error.rb
Class Method Summary collapse
- .data_path ⇒ Object
- .for(criteria, entity_class: self.entity_class, data_path: self.data_path || "") ⇒ Object
- .not_found_error_class_name(data_path) ⇒ Object
- .subclass(mod, entity_class, data_path) ⇒ Object
Instance Method Summary collapse
- #criteria ⇒ Object
- #data_path ⇒ Object
- #entity_class ⇒ Object
- #full_entity_name ⇒ Object
- #primary_key_attribute ⇒ Object
Class Method Details
.data_path ⇒ Object
45 46 47 |
# File 'projects/entities/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 'projects/entities/projects/entity/src/not_found_error.rb', line 34 def for(criteria, entity_class: self.entity_class, data_path: self.data_path || "") = "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:, path: data_path) end |
.not_found_error_class_name(data_path) ⇒ Object
5 6 7 8 |
# File 'projects/entities/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 'projects/entities/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 :symbol do :not_found 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
#criteria ⇒ Object
68 69 70 |
# File 'projects/entities/projects/entity/src/not_found_error.rb', line 68 def criteria context[:criteria] end |
#data_path ⇒ Object
72 73 74 |
# File 'projects/entities/projects/entity/src/not_found_error.rb', line 72 def data_path context[:data_path] end |
#entity_class ⇒ Object
76 77 78 |
# File 'projects/entities/projects/entity/src/not_found_error.rb', line 76 def entity_class context[:entity_class] end |
#full_entity_name ⇒ Object
62 63 64 65 66 |
# File 'projects/entities/projects/entity/src/not_found_error.rb', line 62 def full_entity_name # simplecov:disable entity_class.full_entity_name # simplecov:enable end |
#primary_key_attribute ⇒ Object
56 57 58 59 60 |
# File 'projects/entities/projects/entity/src/not_found_error.rb', line 56 def primary_key_attribute # simplecov:disable entity_class.primary_key_attribute # simplecov:enable end |