Giter Club home page Giter Club logo

macros's Introduction

Trailblazer Coditsu Macros Engine

CircleCI

Set of macros for nicer composition of Trailblazer operations.

Example:

module Repositories
  class Destroy < ApplicationOperation
    step Macros::Model::Find(Repository, :find_by)
    step Macros::Model::Destroy()
  end
end

Table of Contents

Macros types

There are several types of macros organized in namespaces that can be used to do various things with predefined steps.

Contract macros

  • Macros::Contract::Build - Step for setting contract class and building a new contract
  • Macros::Contract::Persist - Step for contract persistance
  • Macros::Contract::Validate - Step for contract validation
module Organizations
  class New < ApplicationOperation
    contract Contracts::Create

    step Macros::Model::Build(Organization)
    step Macros::Contract::Build()
    step Macros::Contract::Validate(key: :organization)
    step Macros::Contract::Persist()
  end
end

Context macros

  • Macros::Ctx::Assign - Assigns a given class to a ctx key for further usage
class Sources < ApplicationOperation
  # Now under the 'model' within context you'll have the Source class
  step Macros::Ctx::Assign(Source)
  step Macros::Model::Fetch(:eligible_for_gc)
end

Error macros

  • Macros::Error::Raise - If we switched to the left track it will raise with some details for debugging
class Vacuum < ApplicationOperation
  step :setup_tables_names
  step :delete_orphaned_offenses

  # Raise an error if anything goes wrong
  failure Macros::Error::Raise(Errors::OperationFailure)
end

Karafka macros

  • Macros::Karafka::Broadcast - Broadcasts a given context field using a given responder
class Create < ApplicationOperation
  step :model_build
  step :model_persist
  step Macros::Karafka::Broadcast(::Users::CreatedResponder)
end

Model macros

  • Macros::Model::Build - Build step for creating new objects from a class/scope
  • Macros::Model::Destroy - Destroy step for removing object assigned in ctx['model']
  • Macros::Model::Fetch - Extracts from a given object from a ctx hash a given attribute/method and assigns it under different key
  • Macros::Model::Find - Searches on a given scope and assigns result to a ctx hash
  • Macros::Model::Import - Import step for mass data import
  • Macros::Model::Paginate - Runs a pagination for a model and reassigns it under the same name
  • Macros::Model::Persist - Persist step for saving object assigned in ctx['model']
  • Macros::Model::Search - Searches based on current_search data and overwrites our model/resource
module Repositories
  class Destroy < ApplicationOperation
    step Macros::Model::Find(Repository)
    step Macros::Model::Destroy()
  end
end

Params macros

  • Macros::Params::Fetch - Fetches a given param key into the ctx hash for further usage
class ScheduleSync < ApplicationOperation
  step Macros::Params::Fetch(from: :build_token)
  step :find_most_recent_status_for_commit_build
  step :schedule_delayed_job
end

Note on contributions

First, thank you for considering contributing to Coditsu ecosystem! It's people like you that make the open source community such a great community!

Each pull request must pass all the RSpec specs and meet our quality requirements.

To check if everything is as it should be, we use Coditsu that combines multiple linters and code analyzers for both code and documentation. Once you're done with your changes, submit a pull request.

Coditsu will automatically check your work against our quality standards. You can find your commit check results on the builds page of Coditsu organization.

coditsu

macros's People

Contributors

mensfeld avatar nijikon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.