abstract class
Orma::Record
- Orma::Record
- Reference
- Object
Defined in:
lib/orma/src/orma/record.crlib/orma/src/orma/record/from_http_params.cr
orma/model_template.cr
orma/orma.cr
orma/scaffolds.cr
Macro Summary
-
accessible(access_model, target_resource, refreshed_template, &blk)
Provides the capability to share records via access tokens.
- boolean_flip_action(name, attr, tpl, &blk)
- create_child_action(name, child_class, parent_id_attr, tpl, &blk)
-
delete_record_action(name, tpl, &blk)
Defines an action to delete the record from the database.
- model_action(name, refreshed_model_template, base_class = Orma::ModelAction, &blk)
- model_template(method_name, wrapper_attributes = nil, &blk)
-
reorder_children_action(name, assoc, child_view, tpl, &blk)
Defines an action to make a list of child models sortable via dragging.
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 theaccess_token
access_view
can be called in the block of theaccessible
call
- A resource providing the
access_view
template- The path will be
/<model_name>/access/<access_token>
- The path will be
#share_uri
, returning the full URI to open theaccess_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)
- Sharing the
- 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 theaccess_view
template
- Its visible template can be defined via the
- 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
macro delete_record_action(name, tpl, &blk)
#
Defines an action to delete the record from the database. Parameters:
name
- the name of the actiontpl
- the model template to render in the response
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 actionassoc
- method of the parent model returning the children collectionchild_view
- method of the child model returning the template to use in the sortable listtpl
- the model template to render in the response