class Roda::Endpoints::Endpoint::Singleton

HTTP endpoint representing a specific item of collection uniquely identified by some parameter.

Attributes

entity[W]
finder[R]

@return [Symbol]

on[R]

@return [Symbol]

Public Class Methods

id_proc(method = nil, &block) click to toggle source
# File lib/roda/endpoints/endpoint/singleton.rb, line 29
def self.id_proc(method = nil, &block)
  block = proc { public_send(method) } if method
  @id_proc = block if block_given?
  @id_proc
end

Public Instance Methods

entity() click to toggle source

@return [ROM::Struct]

# File lib/roda/endpoints/endpoint/singleton.rb, line 42
def entity
  @entity ||= fetch_entity if id
end
fetch_entity() click to toggle source

@return [ROM::Struct]

# File lib/roda/endpoints/endpoint/singleton.rb, line 49
def fetch_entity
  instance_exec(&finder)
end
id() click to toggle source

@return [Integer?]

# File lib/roda/endpoints/endpoint/singleton.rb, line 36
def id
  return instance_eval(&self.class.id_proc) if self.class.id_proc
  @id
end
last_modified() click to toggle source

@return [Time]

# File lib/roda/endpoints/endpoint/singleton.rb, line 54
def last_modified
  @last_modified && entity ? entity.public_send(@last_modified) : super
end