New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

interactor-strict

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interactor-strict

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Interactor::Strict

A stricter version of Interactor.

Gem Version Build Status Maintainability Test Coverage Ruby Style Guide

Getting Started

Add interactor-strict to your Gemfile and bundle install.

gem "interactor-strict"

How to use

Include the Interactor module as well as the Intractor::Strict. That will allow you to use keyword arguments. The of keyword arguments is that you may not miss them, as they will be required by the interpreter. Also, you'll not need to document your params in comments, because the method signature will do that for you.

class SomeService
  include Interactor
  include Interactor::Strict # that will allow you to use keywords

  def call(foo:, bar:, with_default: 'default')
    context.result = [foo, bar, with_default]
  end
end

SomeService.call(foo: "the-foo", bar: "the-bar")

Without the strict interactor module, you would have implemented that service more or less like:

class SomeService
  include Interactor

  def call
    raise "missing foo" if context.foo.nil?
    raise "missing bar" if context.bar.nil?
    context.result = [context.foo, context.bar, context.with_default || "default"]
  end
end

SomeService.call(foo: "the-foo", bar: "the-bar")

Credits

This code started as a fork of mjacobus/interactor.

Disclaimer/Opinion

The Interactor gem provides a DSL for a very common design of service classes in ruby.

I don't particularly support this type of service. I don't like its design because this is not really OOP. Service.call is a function attached to a namespace.

Also, it imposes on your API/Interface, providing a DSL that brings no real value. You should decide how your services should be designed.

However, if you do think Interactor provides a good pattern - or you happen to work in a project that uses this heavily - you are better off with this stricter extension.

FAQs

Package last updated on 25 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc