Class: Inferno::Web::Controllers::Controller

Inherits:
Hanami::Action
  • Object
show all
Defined in:
lib/inferno/apps/web/controllers/controller.rb

Class Method Summary collapse

Class Method Details

.callObject



7
8
9
# File 'lib/inferno/apps/web/controllers/controller.rb', line 7

def self.call(...)
  new.call(...)
end

.inherited(subclass) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/inferno/apps/web/controllers/controller.rb', line 11

def self.inherited(subclass)
  super

  subclass.include Import[repo: "inferno.repositories.#{subclass.resource_name}"]

  subclass.define_method(:serialize) do |*args|
    Inferno::Web::Serializers.const_get(self.class.resource_class).render(*args)
  end

  # Hanami Controller 2.0.0 removes the ability to set a default
  # Content-Type response header, so set it manually if it hasn't been
  # set.
  subclass.after { |_req, res| res.format = :json if res.format == :all && res.body&.first&.first == '{' }
end

.resource_classObject



30
31
32
# File 'lib/inferno/apps/web/controllers/controller.rb', line 30

def self.resource_class
  name.split('::')[-2].singularize
end

.resource_nameObject



26
27
28
# File 'lib/inferno/apps/web/controllers/controller.rb', line 26

def self.resource_name
  name.split('::')[-2].underscore
end