class ResourceKitling::Resource

Attributes

_actions[RW]
subclasses[R]

Public Class Methods

actions(&block) click to toggle source
# File lib/resource_kitling.rb, line 65
def self.actions(&block)
  self._actions ||= ActionCollection.new
  if block_given?
    self._actions.instance_eval(&block)
    self._actions.each do |action|
      if respond_to?(action.name.to_sym)
        raise(
          ArgumentError,
          "Action '#{action.name}' is already defined on `#{self}`"
        )
      end
      method_block = method_for_action(action)
      send(:define_singleton_method, action.name, &method_block)
    end
  end
  self._actions
end
inherited(subclass) click to toggle source
# File lib/resource_kitling.rb, line 58
def inherited(subclass)
  superclass.inherited(subclass) if superclass.respond_to?(:inherited)
  @subclasses ||= []
  @subclasses << subclass
end
method_for_action(action) click to toggle source
# File lib/resource_kitling.rb, line 83
def self.method_for_action(action)
  Proc.new do |*args|
    client = args.shift
    pathopts = action.path.include?(':') ? args.shift : {}
    payload = args.shift
    payload = payload.to_h if payload.respond_to?(:to_h)
    client.call!(
      action.verb, action.generated_path(pathopts), payload, *args
    )
  end
end
new() click to toggle source
# File lib/resource_kitling.rb, line 99
def initialize
end

Public Instance Methods

actions() click to toggle source
# File lib/resource_kitling.rb, line 95
def actions
  self.class.actions
end