Request - response cycle
/insights/:slug
- Routes
- Routes are namespaced per slice
/insights/:slug => "benchmarks.show" => slice/actions/repo/show
- Actions
- Equivalent to controller actions, but each action gets its own file
- Each action explicitly says which view model to use
include Deps[view: "views.benchmarks.show"]
- Views
- e.g.
Main::Views::Benchmarks::Show
-Each instance of a view object is a transformation between input parameters and a rendered view - Documentation: DRY View (Hanami View)
- It contains the hmtl template to use on the render
- It interacts with the
repos
to do any operations - Repos return
Entities
to theview
- The view
expose
s the variables the html template needs - The exposed variables are
Entities
that have been wrapped / decorated asView::Parts
- The inferred name of the
View::Part
is based on theexposure
name, NOT theEntity
class
- e.g.
- Repos
- e.g.
Main::BenchmarkRepo
- Encapsulate the persistence API for
Benchmarks
. - e.g. create, save, find_by
- It defines whether a resource can be created, read, updated or deleted and how that is done.
- Repos never return objects with live connections to the database. This forces you to place
all your persistence logic in here and expose it to higher levels as methods.
- This happens if you materialize your results (
#one
,#to_a
,#one!
). - It is usually bad practice not materialize your results. Some exceptions to this is pagination.
- This happens if you materialize your results (
- Repos return
Entities
or[Entities]
, whose public interface is defined in the correspondingEntity
class. - Internally,
repos
do their work usingROM::Relations
. ROM
is like Rails'ActiveRecord
in the sense that it provides chainable, lazy access to the database using just Ruby.
- e.g.
- Entities
- e.g
Main::Entities::Benchmark < CultureFirst::Entities::Benchmark
- They are very close to a PORO.
- Each
Entity
represents "a thing". - They are powered by
ROM::Struct
, that automatically gives entities access to their attribues based on their entity structure (seeRelation
).
- e.g
- Relations
- e.g.
Persistence::Relations::Benchmarks
- Represents a DB relation (typically maps to 1 table) / single data source.
- An instance of this carries a live connection to the DB
- It is a singleton instance for the lifecycle of the app
- TODO: do associations go here?
- e.g.