only state (๑˃̵ᴗ˂̵)و @subscription_repository = subscription_repository end def call(user) # Input passed in subscription_repository.save(user) end end
require "subscription_repository" SubcriptionRepository.new end MyContainer.register "subscribe_user" do require "subscribe_user" SubscribeUser.new(MyContainer["subscription_repository"]) end MyContainer["subscribe_user"].call(user)
lib/main/operations lib/main/validation lib/main/views ) end # `Main::Views::Home` defined in lib/main/views/home.rb Main::Container["main.views.home"] # => #<Main::Views::Home>
r.on "hello" do # Set variable for all routes in /hello branch @greeting = 'Hello' # GET /hello/world request r.get "world" do "#{@greeting} world!" end end end end
|config| config.routes = "web/routes".freeze config.container = Container end use Rack::Session::Cookie, key: "my_app.session", secret: MyApp::Container.config.app.session_secret route do |r| r.multi_route end load_routes! end end
class Index < Main::View include Main::Import("main.persistence.repositories.users") configure do |config| config.template = "users/index" end def locals(options = {}) {users: users.index(page: options[:page], per_page: options[:per_page])} end end
|create_user| create_user.(r[:user]) do |m| m.success do r.redirect "/users" end m.failure do |errors| r.resolve "main.views.users.new" do |view| view.(params: r[:user], errors: errors) end end end end end end
{}) validation = user_form_schema.(params) if validation.messages.any? Left(validation.messages) else result = create_user.(validation.params) Right(Entities::User.new(result)) end end end
create_user.(r[:user]) do |m| m.success do r.redirect "/users" end m.failure do |errors| r.resolve "main.views.users.new" do |view| view.(params: r[:user], errors: errors) end end end end end end
Users < ROM::Repository relations :users def [](id) users.by_id(id).as(Entities::User).one end def by_email(email) users.where(email: email).as(Entities::User).first end def index(page: 1, per_page: 40) users.per_page(per_page).page(page).as(Entities::User) end end end end end
ROM::Commands::Create[:sql] input Dry::Data["hash"].schema( name: "string", email: "string", encrypted_password: "string", ) relation :users register_as :create result :one end end end
User < Dry::Data::Struct include Dry::Equalizer.new(:id, :name, :email, :encrypted_password) attribute :id, "int" attribute :name, "string" attribute :email, "string" attribute :encrypted_password, "string" end end end