0.0
No release in over 3 years
Low commit activity in last 3 years
Collection of useful macros for Trailblazer to operate on context, contracts, params etc.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

ff-tbl-macros

MIT-LICENSE Gem Version build status

Macros for Trailblazer operations.

Overview

Features

  • several predefined macros organized in namespaces
  • custom macros

Getting Started

Prerequisites

For contributing, install docker to use the provided dockerized development environment.

Installation

Add this line to your application's Gemfile:

gem 'ff-tbl-macros'

Usage

Use the macros in the operation steps:

class User::Delete < Trailblazer::Operation
  step Macros::Model::Destroy()
end

Warning! Rarely some macros may require some gem(s) to be included. Find respective macro down in this file in Macros Types section.

Contributing

Use the provided dockerized development environment. For more information check the CONTRIBUTING file.

Development

The project includes a dockerized development environment.

# build the docker containers
docker-compose build

# run the specs
docker-compose run --rm app bundle exec rspec

Documentation

Macros Types

There are several types of macros organized in namespaces.

Auth Macros

  • Macros::Auth::Authenticate
  • Macros::Auth::SignIn
  • Macros::Auth::SignOut
  • Macros::Auth::SignOutAllScopes
  • Macros::Auth::ExpireSessionData

Contract Macros

  • Macros::Contract::ExtractParams
  • Macros::Contract::Prepopulate

Context Macros

  • Macros::Ctx::Copy
  • Macros::Ctx::Inspect
  • Macros::Ctx::ValidatePresence

Current User Macros

  • Macros::CurrentUser::Set

Error Macros

  • Macros::Error::SetFromContract

Model Macros

  • Macros::Model::Build
  • Macros::Model::Copy
  • Macros::Model::Destroy
  • Macros::Model::Persist

Search Macros

  • Macros::Search::Query

Warning ! If you want to use Macros::Search::Query you have to include pagy gem into ypur Gemfile

Verify Params Macros

  • Macros::VeriryParams::Date

Application Specific Macros

You can create your own custom macros specific to your application. Just put them in the lib/macros folder of your Rails app following this convention:

lib/macros/lorem.rb

module Macros
  class Lorem < Macros::Base
    register :print_ipsum
  end
end

lib/macros/lorem/print_ipsum.rb

module Macros
  class Lorem
    # Some info what your macro does
    #
    # @examples
    #   step Macros::Lorem::PrintIpsum(count:)
    #
    class PrintIpsum < Macros::Base
      def initialize(count:)
        @count = count
      end

      def call(ctx, **)
        @count.times { print 'Ipsum' }
      end
    end
  end
end

License

The gem is available as open source under the terms of the MIT License.

Aknowledgements

Gem used https://github.com/coditsu/macros as the base.