Class: Macros::Base

Inherits:
Object
  • Object
show all
Includes:
Uber::Callable
Defined in:
lib/macros/base.rb

Overview

Base class for all the Trbr step macros

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object

Returns Single step object that can be used in operation step.

Parameters:

  • args

    Any arguments that our macro operation supports



10
11
12
# File 'lib/macros/base.rb', line 10

def initialize(*args)
  self.args = args
end

Class Method Details

.register(step_name, proxy: false) ⇒ Object

To follow Trbr concept of named steps we have to register class instances with given class names - this method registers a class so it can be used with brackets. It will create a method that has a name that has the same name as a class from which we want to use an object to handle a step

Examples:

Register with :create

register :create #=> Macros::Create()

Parameters:

  • step_name (Symbol)

    name that we want to use

  • proxy (Boolean) (defaults to: false)

    is this just a proxy for Trailblazer built in operation



24
25
26
27
28
29
30
31
# File 'lib/macros/base.rb', line 24

def self.register(step_name, proxy: false)
  klass = step_name.to_s.split('_').collect(&:capitalize).join

  define_singleton_method klass do |*args|
    base = "#{self}::#{klass}".constantize
    proxy ? base.new(*args).call : base.new(*args)
  end
end