0.0
No release in over 3 years
Low commit activity in last 3 years
Shirinji integration for rails (see https://github.com/fdutey/shirinji for more details)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 10.0
~> 3.0

Runtime

>= 5.0.0
>= 0.0.3
 Project Readme

Shirinji-Rails

Integration of Shirinji in rails

Installation

Add this line to your application's Gemfile:

gem 'shirinji-rails'

And then execute:

$ bundle

General usage

Add this file in config/dependencies.rb

Shirinji::Map.new do
  # declare your dependencies here
end

Dependency resolver can be accessed through

Rails.application.config.shirinji.resolver

I suggest to use a helper to make your life easier.

# lib/my_app.rb

module MyApp
  module_function
  
  def bean(name)
    ::Rails.application.config.shirinji.resolver.resolve(name)
  end
end

# moments later, in controllers / job / rake tasks
service = MyApp.bean(:user_sign_up_service)
service.call(user) 

Rails entities DSL

Since controllers and jobs (and maybe other rails entities) are not under Shirinji's control, they can not receive dependencies through their constructors.

One solution is to manually create a method for each dependency but it's painful and make the code harder to read.

Rails integration actually provides a simple DSL to express dependencies.

# application_controller.rb

class ApplicationController < ActionController::Base 
  include ShirinjiRails::ResolverBinding
end

# in any controller

class FooController < ApplicationController
  dependency :config
  # Alias
  dependency foo_create_service: :create_service
  
  def index
    config #=> `config` dependency
    create_service # => `foo_create_service` dependency 
  end
end

class FooJob < ActiveJob::Base
  include ShirinjiRails::ResolverBinding

  dependency :config
 
  def perform
    config #=> `config` dependency
  end
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/fdutey/shirinji-rails.