Class: Pakyow::Routing::Framework

Inherits:
Object
  • Object
show all
Defined in:
lib/pakyow/routing/framework.rb

Instance Method Summary collapse

Instance Method Details

#bootObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/pakyow/routing/framework.rb', line 20

def boot
  object.class_eval do
    include Pakyow::Application::Behavior::Routing::Definition

    isolate Controller do
      include Extension::Resource
    end

    # Make controllers definable on the app.
    #
    stateful :controller, isolated(:Controller) do |args, _opts|
      if self.ancestors.include?(Plugin)
        # When using plugins, prefix controller paths with the mount path.
        #
        name, matcher = Controller.send(:parse_name_and_matcher_from_args, *args)
        path = File.join(@mount_path, Controller.send(:path_from_matcher, matcher).to_s)
        args.replace([name, path])
      end
    end

    # Load controllers for the app.
    #
    aspect :controllers

    # Load resources for the app.
    #
    aspect :resources

    register_helper :active, Helpers::Exposures

    # Include helpers into the controller class.
    #
    on "load" do
      self.class.include_helpers :active, isolated(:Controller)
    end

    # Create the global controller instance.
    #
    after "initialize" do
      @global_controller = isolated(:Controller).new(self)
    end

    # Expose the global controller for handling errors from other frameworks.
    #
    def controller_for_connection(connection)
      @global_controller.dup.tap do |controller|
        controller.instance_variable_set(:@connection, connection)
      end
    end

    require "pakyow/support/message_verifier"
    handle Support::MessageVerifier::TamperedMessage, as: :forbidden

    include Security::Config
    include Security::Behavior::Disabling
    include Security::Behavior::Helpers
    include Security::Behavior::Insecure
    include Security::Behavior::Pipeline
  end
end