class Servicer::Base

This is base class for subclassing your services. Example:

class MyClass < ::Servicer::Base
  layer :require_user

  def call(current_user, params)
    true
  end
end

MyClass.call(current_user, params)

Attributes

current_user[R]
params[R]

Public Class Methods

call(current_user, params) click to toggle source

Main call. Will create instance and run `call` on it. In most cases instance method should be overwritten.

# File lib/servicer/base.rb, line 33
def call(current_user, params)
  current_user, params = layers.inject([current_user, params]) { |arr, layer| layer.call(arr[0], arr[1]) }
  new(current_user, params).call
end
layer(layer_class, options = {}, &block) click to toggle source

Apply layer. Layer class can be any class based on ::Servicer::Layers::Base or symbolized name of layer.

# File lib/servicer/base.rb, line 27
def layer(layer_class, options = {}, &block)
  layer_class = ::Servicer::Layers.const_get(layer_class.to_s.camelcase) if layer_class.is_a?(Symbol)
  layers << layer_class.new(options, &block)
end
layers() click to toggle source
# File lib/servicer/base.rb, line 22
def layers
  @layers ||= []
end
new(current_user, params) click to toggle source
# File lib/servicer/base.rb, line 44
def initialize(current_user, params)
  @current_user = current_user
  @params = params
end

Public Instance Methods

call() click to toggle source

Main call. Overwrite this.

# File lib/servicer/base.rb, line 40
def call; end