Skip to content

Instantly share code, notes, and snippets.

@timriley
Created November 13, 2023 19:06
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 timriley/27b8aa4c1e805dc6acb68a2b836252b8 to your computer and use it in GitHub Desktop.
Save timriley/27b8aa4c1e805dc6acb68a2b836252b8 to your computer and use it in GitHub Desktop.
Hanami deps demo with a view
# frozen_string_literal: true
module Rubyconf2023
module Views
module Posts
class Index < Rubyconf2023::View
include Deps["repos.post_repo"]
# the below is generated courtesy of dry-auto_inject (which hanami configures to work with
# its app/slice containers)
# def self.new(post_repo: nil)
# post_repo ||= Rubyconf2023::Container["repos.post_repo"]
# super(post_repo:)
# end
# attr_reader :post_repo
# def initialize(post_repo:)
# super()
# @post_repo = post_repo
# end
expose :posts do
post_repo.all
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment