class HecksAdapters::SQLDatabase::Commands::Read

Read a resource

Attributes

entity[R]
head[R]
id[R]
table[R]

Public Class Methods

new(id:, head:, entity_class:) click to toggle source
# File lib/commands/read.rb, line 9
def initialize(id:, head:, entity_class:)
  @head = head
  @table = Table.factory([@head]).first
  @id = id
  @entity_class = entity_class
end

Public Instance Methods

call() click to toggle source
# File lib/commands/read.rb, line 16
def call
  fetch_entity
  return if @entity.nil?
  @entity_class.new(
    @entity.merge(FetchReferences.new(self).call.reference_map)
  )
end

Private Instance Methods

fetch_entity() click to toggle source
# File lib/commands/read.rb, line 26
def fetch_entity
  @entity = DB[@table.name.to_sym].first(id: @id)
end