ff-tbl-macros
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()
endWarning! 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::AuthenticateMacros::Auth::SignInMacros::Auth::SignOutMacros::Auth::SignOutAllScopesMacros::Auth::ExpireSessionData
Contract Macros
Macros::Contract::ExtractParamsMacros::Contract::Prepopulate
Context Macros
Macros::Ctx::CopyMacros::Ctx::InspectMacros::Ctx::ValidatePresence
Current User Macros
Macros::CurrentUser::Set
Error Macros
Macros::Error::SetFromContract
Model Macros
Macros::Model::BuildMacros::Model::CopyMacros::Model::DestroyMacros::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
endlib/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
endLicense
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.