abstract class Orma::Record

Defined in:

lib/orma/src/orma/record.cr
lib/orma/src/orma/record/from_http_params.cr
orma/model_template.cr
orma/orma.cr
orma/scaffolds.cr

Macro Summary

Macro Detail

macro accessible(access_model, target_resource, refreshed_template, &blk) #

Provides the capability to share records via access tokens.

Adds the following to the model:

  • An access_token column that will be populated automatically
  • The access_view macro which defines a template to be shown when opening a link containing the access_token
    • access_view can be called in the block of the accessible call
  • A resource providing the access_view template
    • The path will be /<model_name>/access/<access_token>
  • #share_uri, returning the full URI to open the access_view
  • #share_element, returning a wrapper template that will attempt to trigger sharing capabilities on the client device on click
    • Sharing the #share_uri via the Web Share API (mostly on mobile devices)
    • Writing the #share_uri to the device clipboard via the Clipboard API (usually only available in secure contexts)
  • A model action to accept access
    • Its visible template can be defined via the accept_access_view template macro
    • Should be included via #accept_access_action_template in the access_view template
  • The access_model_attributes macro, accepting a NamedTuple parameter
    • The given attributes will be added to the access model instance that is created when a user accepts the access via the model action

NOTE This macro is about sharing and granting access, not about restricting it. Any Resource showing this model has to be made aware of any restrictions by other means.

Example usage:

class GroupMember < ApplicationRecord
  column session_id : String
end

class Group < ApplicationRecord
  [...]

  model_template :member_list do
    [...]
  end

  accessible GroupMember, GroupResource, member_list do
    access_view do
      template do
        h1 { "Join!" }

        model.accept_access_action_template
      end
    end

    accept_access_view do
      template do
        button { "Join" }
      end
    end

    access_model_attributes session_id: ctx.session.id.to_s
  end
end

[View source]
macro boolean_flip_action(name, attr, tpl, &blk) #

[View source]
macro create_child_action(name, child_class, parent_id_attr, tpl, &blk) #

[View source]
macro delete_record_action(name, tpl, &blk) #

Defines an action to delete the record from the database. Parameters:

  • name - the name of the action
  • tpl - the model template to render in the response

[View source]
macro model_action(name, refreshed_model_template, base_class = Orma::ModelAction, &blk) #

[View source]
macro model_template(method_name, wrapper_attributes = nil, &blk) #

[View source]
macro reorder_children_action(name, assoc, child_view, tpl, &blk) #

Defines an action to make a list of child models sortable via dragging. Parameters:

  • name - the name of the action
  • assoc - method of the parent model returning the children collection
  • child_view - method of the child model returning the template to use in the sortable list
  • tpl - the model template to render in the response

[View source]