Project

angostura

0.0
No commit activity in last 3 years
No release in over 3 years
Add dependency setup hook to components easily.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Angostura Dependency Gem

Angostura Leaf

Angostura adds an easy way to setup component dependencies inspired by rails engine setup guides.

Angostura expands upon the basic idea of using a mattr_accessor adding validation to ensure using stringified class names during setup, ensure that dependencies were set, and provide default values.

Great, how do I use it?

The simplest usage just sets a few dependencies by including angostura and using the dependendency hook with an arg or two.

module GreatComponent
  include Angostura::Dependencies

  dependency :user, :authorizer
end

With this GreatComponent now responds to GreatComponent.user returning the setup string and GreatComponent.user_class returning the class object.

GreatComponent also now has an available setup method to be used in an initializer.

GreatComponent.setup do |config|
  config.user = 'PoorChoices'
end

Config expects stringified class names, angostura will dynamically define a dependency_class method for you which returns the constantized class.

The dependency hook also allows you to set defaults for the dependency by passing keyword arguments. For example dependency :house, car: 'Mazerati', a dependency with a default can still of course be overriden in the setup block.

That's it, that's all. It's a simple small gem.