Skip to content

Instantly share code, notes, and snippets.

@flash-gordon
Created June 6, 2016 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flash-gordon/03815c23b8a3310e96bcfc3771a73be2 to your computer and use it in GitHub Desktop.
Save flash-gordon/03815c23b8a3310e96bcfc3771a73be2 to your computer and use it in GitHub Desktop.
repo example
source "https://rubygems.org"
ruby "2.3.1"
# Web framework
gem "dry-web", github: "dry-rb/dry-web"
# Database persistence
gem "sqlite3"
gem "rom", github: "rom-rb/rom"
gem "rom-mapper", github: "rom-rb/rom-mapper"
gem "rom-repository", github: "rom-rb/rom-repository"
gem "rom-sql", github: "rom-rb/rom-sql"
gem "rom-support", github: "rom-rb/rom-support"
gem "dry-auto_inject", github: "dry-rb/dry-auto_inject"
gem "pg"
# Application dependencies
gem 'rake'
gem "dry-validation", github: "dry-rb/dry-validation"
group :test do
gem "rspec"
gem "rack-test"
end
require 'bundler'
Bundler.require
class Container
extend Dry::Container::Mixin
namespace(:persistence) do
config = ROM::Configuration.new(default: [:sql, 'postgres://localhost/rom_repo_test'])
register(:rom, ROM.container(config))
namespace(:repo) do
register(:posts) { Persistence::Repo::Posts.new }
end
end
Import = Dry::AutoInject(self)
ArgsImport = Import.args
end
module Persistence
module Repo
class Posts < ROM::Repository[:posts]
include Container::ArgsImport['persistence.rom']
def index
root.to_a
end
end
end
end
p Container['persistence.repo.posts'].index # => [#<ROM::Struct[Post] id=1 body="foo">]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment