Skip to content

fobiasmog/opisator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Opisator

The main idea of this gem is to remove any logic from controllers and simply describe, how a controller should work with request and it's data.

You feel free to use any gems and conceptions (for example: dry-rb, interaction gems, json serializers) inside you contract, interactor and presenter moudles

class IndexController < ApplicationController
  include Opisator

  opisator_for :index

  def index
    @contract = MyContracts::Index
    @interactor = MyInteractors::Index
    @presenter = MyPresenters::Index
  end
end

There is the simple pipline of interaction:

request -> contract(params) -> interactor(contract_result) -> presenter(interactor_result) -> render(presenter_result)

Contracts

Params from request are passing directly to contract module, so you can validate, permit and change it whatever you want.

class Contracts::Index
  def call(params)
    validate_and_return_params
  end
end

Interactors

Any business-logic is should be inside interactor

class Interactors::Index
  def call(params)
    pp 'index interactor'
  end
end

Presenters

Presenters are using for prepare data to render. You have to return hash, which pass to rails render function

class Presenters::Index
  def call(params)
    {
      json: { ok: true },
      status: 201
    }
  end
end

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages