No commit activity in last 3 years
No release in over 3 years
Copy interactor context on specified object's instance variables to allow easier interaction with returned values
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
>= 0
>= 0
~> 2.14.0

Runtime

 Project Readme

Interactor CopyContext

This gem allows you to easily extend interactor so that in Ruby on Rails you can eventually copy the context on your controller as @instace_variables, accessing them easily. Here is an example:

class MakeCake
  include Interactor
  
  def perform
    # dosomething
  end
end

class CakesController < ApplicationController
  
  def create
    MakeCake.perform_on(self, ingredients: [:egg, :milk, :something])
    
    render text: @ingredients.first.to_s # => "egg"
  end
  
end

Installation

Add this line to your application's Gemfile:

gem 'interactor-copy_context', '~> 0.0.3'

And then execute:

$ bundle

Or install it yourself as:

$ gem install interactor-copy_context

Usage

Usage is very simple, use the method perform_on which is just a wrapper for perform (accepts same params). The only important thing is first parameter is the object which you want to inject context into. So for example, self in a controller is the controller itself, very helpful because data is ready for your views in that case. The method is available both on Interactor and organizer and on instance and class too.

DummyInteractor.perform_on(self, dummy1: 'blah')
DummyInteractor.new(dummy1: 'blah').perform_on(self)

Both methods inject same context, so they are equivalent. Same for organizer methods (they behave like interactors):

DummyOrganizer.perform_on(self)
DummyOrganizer.new.perform_on(self)

About performance

It's a copy of an entire hash (not a deep copy, only pointers). I don't think context will ever grow over 100 elements, so it should be fine.

Contributing

  1. Fork it ( https://github.com/[my-github-username]/interactor-copy_context/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request