https://github.com/justindoody/angostura
Easily add component dependencies
https://github.com/justindoody/angostura
components dependencies engines rails rails-engine ruby
Last synced: 3 months ago
JSON representation
Easily add component dependencies
- Host: GitHub
- URL: https://github.com/justindoody/angostura
- Owner: justindoody
- Created: 2017-02-21T21:44:21.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-02T20:10:18.000Z (about 8 years ago)
- Last Synced: 2024-10-31T14:13:04.429Z (8 months ago)
- Topics: components, dependencies, engines, rails, rails-engine, ruby
- Language: Ruby
- Homepage:
- Size: 1.25 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Angostura Dependency Gem

Angostura adds an easy way to setup component dependencies inspired by [rails engine setup guides](http://guides.rubyonrails.org/engines.html#configuring-an-engine).
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.
```ruby
module GreatComponent
include Angostura::Dependenciesdependency :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.
```ruby
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.