Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

untangle

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

untangle

  • 0.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Untangle

This gem provides a very lightweight API to specify dependencies between objects. The key concepts behind it are:

  • Make dependencies of your objects visible by declaring them
  • Depend on roles, not implementation
  • Simplify testing by substituting your dependencies with mocks

Installation

gem install untangle

Define Dependencies

explicit

Explicit definitions contain a direct reference to the actual dependency. The reference can either be a String:

class Person
  extend Untangle

  dependency :translator, 'I18n'
end

or a block:

class Person
  extend Untangle

  dependency(:translator) { I18n }
end

implicit

Implicit definitions have no reference to the actual dependency. The implementation will be inferred from the name. In the following example, the dependency would resolve to Translator.

class Person
  extend Untangle

  dependency :translator
end

Global Dependencies

If you have global dependencies, which are used throughout your app, you can register them globally. This way you can use dependency implicit definitions without a name that corresponds to the implementation.

Untangle.register :translator, 'I18n'

class Blog
  extend Untangle

  dependency :translator
end

You can also use these registered dependencies to inject them into a constructor. This technique does not require that the object under construction knows about explicit_dependencies

Untangle.register :translator, 'I18n'
ExplicitDependencies.register :people_repository, 'PeopleRepository'

class MyPrcoess

  # The argument names must match the registered dependencies
  def initialize(translator, people_repository)
  end

end

Untangle.inject(MyProcess, :new)

Testing

FAQs

Package last updated on 23 Dec 2012

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