Skip to content
/ rdm Public
forked from droidlabs/rdm

The missing dependency manager for Ruby applications

License

Notifications You must be signed in to change notification settings

ddd-ruby/rdm

 
 

Repository files navigation

Rdm (Ruby Dependecy Manager)

Build Status Code Climate codecov Dependency Status

Ruby dependency manager, helps managing local package dependencies. See sample application in "example" folder.

Setup

You can initialize a project with rdm:

$ mkdir my_project && rdm init

Alternatively you could manually create the an Rdm.packages file with similar content in your existing project:

setup do
  role                ENV['RUBY_ENV'] || 'production'
  configs_dir         'configs'
  config_path         ":configs_dir/:config_name/default.yml"
  role_config_path    ":configs_dir/:config_name/:role.yml"
  package_subdir_name 'package'
end

config :database
config :app

package 'server'
package 'application/web'
package 'domain/core'
package 'infrastructure/repository'

Generating new packages

# see available options
$ rdm gen.package -h

# generate commands package in a relative path to root directory
$ rdm gen.package commands --path core/application/commands

Example Package.rb

package do
  name    'system_bus'
  version '1.0.0'
end

dependency do
  import 'utils'
end

dependency :test do
  import 'repository'
  import 'database'
  import 'events'
end

Rough Idea

Rdm positions itself somewhere between Ruby gems and Rails engines. It allows you to define clear boundaries in your application by splitting it up in application-level, framework-agnostic packages. Each package defines in its Package.rb file clear dependencies on other packages / gems for each environment.

When you boot a package (eg. by loading it in IRB), only defined dependencies are available to you. This is done by letting Rdm manage the Ruby-$LOAD_PATH behind the scenes for you.

All packages share the same Gemfile, but get access to only explicitly defined subset of gems / packages from the Package.rb file

When needed you can ask Rdm to programmatically give you dependencies for a particular package and use it. At DroidLabs we use this to generate very lightweight Dockerimages with just the necessary dependencies for each application.

Rules of RDM to structure big Ruby applications

  • define all your gems in Gemfile to be lazily loaded, like gem 'sequel', '4.41.0', require: false

  • name your classes / modules after Rails-established conventions, so files are loaded only on demand, when encountering a new class / module constant (const_missing from ActiveSupport)

  • use a Dependency Injection library with lazy-loading support, we recommend smart_ioc

Loading Rdm

Setup RDM in boot.rb or spec_helper.rb or any other initializer. Rdm.init should point to a directory with Package.rb-file

require 'rdm'
Rdm.init(File.expand_path("../../", __FILE__), :test)

Examples

About

The missing dependency manager for Ruby applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 99.9%
  • Other 0.1%