About Hanami have already written on Habré , and the team has something to rejoice:
Freezing features, project-level logger, automatic logging of HTTP requests, SQL requests and migrations. Minor bug fixes.
The release of v1.0.0.beta1
freezes the development of new functionality for Hanami 1.0, but at the same time adds a couple of new features and a few fixes.
From now on, Hanami API's will remain stable until version 2.0 .
A stable release ( v1.0.0
) is expected between the end of March and the beginning of April 2017, which coincides with the tradition of admiring the blossoming Sakura (Hanami) in Japan .
During this time, the Hanami team will release other beta and release candidate versions.
Hanami is now compatible with Ruby 2.3+ (including the latest 2.4) and Rack only 2.0.
We have added a project level logger, available as Hanami.logger
. If you need to log something, do something like this: Hanami.logger.debug "hello"
.
For this reason, application level loggers had to be removed (eg. Web.logger
, Admin.logger
).
Consequently, logging settings for individual applications are no longer supported (i.e., inside apps/web/application.rb
). To configure the logger, edit config/environment.rb
.
A project built on Hanami can automatically log incoming HTTP requests, SQL requests and migrations.
When the project is launched in development mode, the log format looks more readable:
[bookshelf] [INFO] [2017-02-11 15:42:48 +0100] HTTP/1.1 GET 200 127.0.0.1 /books/1 451 0.018576 [bookshelf] [INFO] [2017-02-11 15:42:48 +0100] (0.000381s) SELECT "id", "title", "created_at", "updated_at" FROM "books" WHERE ("book"."id" = '1') ORDER BY "books"."id"
For production, by contrast, JSON has become the default format. JSON is easier to parse and it is more machine-oriented. This works well with SaaS log aggregators.
{"app":"bookshelf","severity":"INFO","time":"2017-02-10T22:31:51Z","http":"HTTP/1.1","verb":"GET","status":"200","ip":"127.0.0.1","path":"/books/1","query":"","length":"451","elapsed":0.000391478}
Migrations will write to the standard output stream of the operation performed with the database schema.
➜ bundle exec hanami db migrate [hanami] [INFO] Begin applying migration 20170213123250_create_books.rb, direction: up [hanami] [INFO] (0.001756s) CREATE TABLE `books` (`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `name` varchar(255) NOT NULL, `created_at` timestamp NOT NULL, `updated_at` timestamp NOT NULL) [hanami] [INFO] (0.001738s) INSERT INTO `schema_migrations` (`filename`) VALUES ('20170213123250_create_books.rb') [hanami] [INFO] Finished applying migration 20170213123250_create_books.rb, direction: up, took 0.004091 seconds
The model generator now also creates a migration file for the entity it generates.
➜ bundle exec hanami generate model book create lib/bookshelf/entities/book.rb create lib/bookshelf/repositories/book_repository.rb create db/migrations/20170213123250_create_books.rb create spec/bookshelf/entities/book_spec.rb create spec/bookshelf/repositories/book_repository_spec.rb
This will generate the entity, as well as the corresponding repository, migration, and test patterns.
Migrations immediately contain code to create a table, a primary key, and timestamps.
# db/migrations/20170213123250_create_books.rb Hanami::Model.migration do change do create_table :books do primary_key :id column :created_at, DateTime, null: false column :updated_at, DateTime, null: false end end end
config/boot.rb
New projects will be created with a new file: config/boot.rb
require_relative './environment' Hanami.boot
This is useful for starting Hanami's environment services, especially without access to a server or console. A typical scenario - Sidekiq Sidekiq . If you want to run asynchronous tasks with this message queue, start the process like this:
bundle exec sidekiq -r ./config/boot.rb
For a complete list of changes, see the CHANGELOG and features list .
hanami-1.0.0.beta1
hanami-model-1.0.0.beta1
hamami-controller-1.0.0.beta1
hanami-assets-1.0.0.beta1
hanami-mailer-1.0.0.beta1
hanami-helpers-1.0.0.beta1
hanami-view-1.0.0.beta1
hanami-validations-1.0.0.beta1
hanami-router-1.0.0.beta1
hanami-utils-1.0.0.beta1
We are grateful to each of those who helped release the release. Here is a list of these wonderful people:
If you want to update your project from v0.9
, pay attention to the upgrade guide .
Since the final release is just around the corner, it's time to finally try this framework if you haven't done it yet.
For those who are accustomed to read in Russian - good news: the translation of official documentation and guides is already underway. Look in pool requests, join, send your own.
Source: https://habr.com/ru/post/321938/
All Articles