module ReSorcery::Linked::ClassMethods
Private Instance Methods
links(&block)
click to toggle source
Define a set of ‘Link`s for a class
The block is evaluated in the context of an instance of the class, so the set of ‘Link`s can be contextualized. For example, if the current user doesn’t have permissions to edit the object, the “update” ‘Link` can be left out:
class MyObject include Linked attr_reader :id, :current_user def initialize(id, current_user) @id = id @current_user = current_user end links do link 'self', "/my_objects/#{id}" link 'update', "/my_objects/#{id}", 'put' if current_user.can_update?(self) link 'destroy', "/my_objects/#{id}", 'delete' if current_user.can_destroy?(self) end end
The result of calling the block is not cached.
# File lib/re_sorcery/linked.rb, line 36 def links(&block) @links_proc = block end