Created
June 6, 2016 17:07
-
-
Save flash-gordon/03815c23b8a3310e96bcfc3771a73be2 to your computer and use it in GitHub Desktop.
repo example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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