Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.