module Evvnt::Actions
Internal: Methods for defining API actions for each resource Class.
Public Instance Methods
first()
click to toggle source
The first record from the API index actions
Returns {Evvnt::Base} subclass
# File lib/evvnt/actions.rb, line 9 def first defined_actions.include?(:index) ? all.first : method_missing(:first) end
last()
click to toggle source
The last record from the API index actions
Returns {Evvnt::Base} subclass
# File lib/evvnt/actions.rb, line 17 def last defined_actions.include?(:index) ? all.first : method_missing(:last) end
Private Instance Methods
define_action(action, &block)
click to toggle source
Define an action for this class to map on to the Evvnt
API for this class's resource.
action - A Symbol or String representing the action name. Should be one of the
template actions if block is not provided.
block - A Proc to be used as the action method definition when custom behaviour
is required.
Examples
class Package < Evvnt::Base # Define using the template `all` method define_action :all define_action :mine do # define the custom behaviour here end end
Returns Symbol
# File lib/evvnt/actions.rb, line 51 def define_action(action, &block) action = action.to_sym defined_actions << action unless defined_actions.include?(action) if action.in?(Evvnt::ClassTemplateMethods.instance_methods) define_class_action(action, &block) end if action.in?(Evvnt::InstanceTemplateMethods.instance_methods) define_instance_action(action, &block) end action end
define_class_action(action, &block)
click to toggle source
Define a class-level action on the current class. See {define_action}.
# File lib/evvnt/actions.rb, line 64 def define_class_action(action, &block) body = block_given? ? block : ClassTemplateMethods.instance_method(action) define_singleton_method(action, body) singleton_class.send(:alias_method, :all, :index) if action == :index singleton_class.send(:alias_method, :find, :show) if action == :show end
define_instance_action(action, &block)
click to toggle source
Define an instance-level action on the current class. See {define_action}.
# File lib/evvnt/actions.rb, line 72 def define_instance_action(action, &block) body = block_given? ? block : InstanceTemplateMethods.instance_method(action) define_method(action, body) end
defined_actions()
click to toggle source
A list of the API actions defined on this class
Returns Array
# File lib/evvnt/actions.rb, line 27 def defined_actions @defined_actions ||= [] end