onyxframework / onyx

Powerful framework for modern applications 💪
https://api.onyxframework.com/onyx
MIT License
78 stars 5 forks source link

Separate namespaces for modules #16

Closed vladfaust closed 5 years ago

vladfaust commented 5 years ago
require "onyx/http"

Onyx::HTTP.get "/", &.response.puts("Hello World!")
Onyx::HTTP.routes do
  on "user" do
    get "/:id", Endpoint::User::Get
    post "/", Endpoint::User::Create
  end
end

user = Onyx::SQL.query(Model::User.where(id: params.query.id)).first?

sub = Onyx::EDA.memory.subscribe(Event::MyEvent) do |e|
  puts e.foo
end

The idea is to isolate top-level macros into modules, with these changes:

Onyx.get -> Onyx::HTTP.get
Onyx.query -> Onyx::SQL.query
Onyx.memory.emit -> Onyx::EDA.memory.emit # .memory is upcoming API change

This would, indeed, require to write more code, but bring better transparency to the codebase and eliminate possible clashes between methods. For example, options can both be used to define an HTTP endpoint and to configure something. The same for delete.