pakyow-core 1.0.0.rc5 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/lib/pakyow/{environment/actions → actions}/dispatch.rb +0 -0
  4. data/lib/pakyow/{environment/actions → actions}/input_parser.rb +0 -0
  5. data/lib/pakyow/{environment/actions → actions}/logger.rb +0 -0
  6. data/lib/pakyow/{environment/actions → actions}/normalizer.rb +0 -0
  7. data/lib/pakyow/{app.rb → application.rb} +26 -26
  8. data/lib/pakyow/application/behavior/aspects.rb +51 -0
  9. data/lib/pakyow/application/behavior/endpoints.rb +43 -0
  10. data/lib/pakyow/application/behavior/frameworks.rb +47 -0
  11. data/lib/pakyow/application/behavior/helpers.rb +107 -0
  12. data/lib/pakyow/{environment → application}/behavior/initializers.rb +4 -4
  13. data/lib/pakyow/application/behavior/isolating.rb +71 -0
  14. data/lib/pakyow/application/behavior/operations.rb +49 -0
  15. data/lib/pakyow/application/behavior/pipeline.rb +60 -0
  16. data/lib/pakyow/application/behavior/plugins.rb +151 -0
  17. data/lib/pakyow/application/behavior/rescuing.rb +53 -0
  18. data/lib/pakyow/application/behavior/restarting.rb +72 -0
  19. data/lib/pakyow/application/behavior/sessions.rb +38 -0
  20. data/lib/pakyow/{behavior → application}/config.rb +1 -1
  21. data/lib/pakyow/{app → application}/connection.rb +4 -4
  22. data/lib/pakyow/{app → application}/connection/behavior/session.rb +1 -1
  23. data/lib/pakyow/{app → application}/connection/behavior/values.rb +1 -1
  24. data/lib/pakyow/{app → application}/connection/behavior/verifier.rb +1 -1
  25. data/lib/pakyow/{app → application}/connection/session/base.rb +1 -1
  26. data/lib/pakyow/{app → application}/connection/session/cookie.rb +2 -2
  27. data/lib/pakyow/application/helpers/app.rb +30 -0
  28. data/lib/pakyow/application/helpers/connection.rb +47 -0
  29. data/lib/pakyow/behavior/initializers.rb +3 -3
  30. data/lib/pakyow/behavior/input_parsing.rb +55 -0
  31. data/lib/pakyow/behavior/plugins.rb +3 -130
  32. data/lib/pakyow/behavior/restarting.rb +28 -46
  33. data/lib/pakyow/behavior/running.rb +127 -0
  34. data/lib/pakyow/behavior/silencing.rb +21 -0
  35. data/lib/pakyow/behavior/timezone.rb +19 -0
  36. data/lib/pakyow/behavior/verification.rb +1 -1
  37. data/lib/pakyow/behavior/verifier.rb +30 -0
  38. data/lib/pakyow/behavior/watching.rb +73 -0
  39. data/lib/pakyow/config.rb +168 -0
  40. data/lib/pakyow/environment.rb +31 -31
  41. data/lib/pakyow/helper.rb +9 -0
  42. data/lib/pakyow/loader.rb +7 -1
  43. data/lib/pakyow/plugin.rb +22 -21
  44. metadata +42 -42
  45. data/lib/pakyow/behavior/aspects.rb +0 -49
  46. data/lib/pakyow/behavior/endpoints.rb +0 -41
  47. data/lib/pakyow/behavior/frameworks.rb +0 -45
  48. data/lib/pakyow/behavior/helpers.rb +0 -108
  49. data/lib/pakyow/behavior/isolating.rb +0 -69
  50. data/lib/pakyow/behavior/operations.rb +0 -47
  51. data/lib/pakyow/behavior/pipeline.rb +0 -58
  52. data/lib/pakyow/behavior/rescuing.rb +0 -51
  53. data/lib/pakyow/behavior/sessions.rb +0 -36
  54. data/lib/pakyow/environment/behavior/config.rb +0 -172
  55. data/lib/pakyow/environment/behavior/input_parsing.rb +0 -57
  56. data/lib/pakyow/environment/behavior/plugins.rb +0 -23
  57. data/lib/pakyow/environment/behavior/restarting.rb +0 -54
  58. data/lib/pakyow/environment/behavior/running.rb +0 -129
  59. data/lib/pakyow/environment/behavior/silencing.rb +0 -23
  60. data/lib/pakyow/environment/behavior/timezone.rb +0 -21
  61. data/lib/pakyow/environment/behavior/verifier.rb +0 -32
  62. data/lib/pakyow/environment/behavior/watching.rb +0 -75
  63. data/lib/pakyow/helpers/app.rb +0 -28
  64. data/lib/pakyow/helpers/connection.rb +0 -45
@@ -1,108 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
- require "pakyow/support/makeable"
5
- require "pakyow/support/safe_string"
6
-
7
- require "pakyow/helpers/app"
8
- require "pakyow/helpers/connection"
9
-
10
- module Pakyow
11
- module Helper
12
- extend Support::Makeable
13
- end
14
-
15
- module Behavior
16
- # Maintains a list of helper modules, with code for including helpers of a type into an object.
17
- #
18
- # Helpers are either global, passive, or active. Global helpers contain utility methods or
19
- # methods that need application-level state. Passive helpers can access state on the connection
20
- # but never change connection state, which active helpers are solely responsible for doing.
21
- #
22
- module Helpers
23
- extend Support::Extension
24
-
25
- apply_extension do
26
- class_state :__included_helpers, default: {}, inheritable: true
27
-
28
- setting :helpers,
29
- global: [
30
- Pakyow::Helpers::App,
31
- Support::SafeStringHelpers
32
- ],
33
-
34
- passive: [
35
- Pakyow::Helpers::Connection
36
- ],
37
-
38
- active: []
39
-
40
- on "load" do
41
- # Helpers are loaded first so that other aspects inherit them.
42
- #
43
- load_aspect(:helpers)
44
-
45
- self.class.state(:helper).each do |helper|
46
- context = if helper.instance_variable_defined?(:@type)
47
- helper.instance_variable_get(:@type)
48
- else
49
- :global
50
- end
51
-
52
- self.class.register_helper(context, helper)
53
- end
54
- end
55
-
56
- # Define helpers as stateful after an app is made.
57
- #
58
- after "make", priority: :high do
59
- stateful :helper, Helper
60
- end
61
- end
62
-
63
- class_methods do
64
- # Registers a helper module to be loaded on defined endpoints.
65
- #
66
- def register_helper(context, helper_module)
67
- (config.helpers[context.to_sym] << helper_module).uniq!
68
- end
69
-
70
- # Includes helpers of a particular context into an object. Global helpers
71
- # will automatically be included into active and passive contexts, and
72
- # passive helpers will automatically be included into the active context.
73
- #
74
- def include_helpers(context, object)
75
- @__included_helpers[object] = context
76
-
77
- helpers(context.to_sym).each do |helper|
78
- object.include helper
79
- end
80
- end
81
-
82
- def helpers(context)
83
- case context.to_sym
84
- when :global
85
- config.helpers[:global]
86
- when :passive
87
- config.helpers[:global] + config.helpers[:passive]
88
- when :active
89
- config.helpers[:global] + config.helpers[:passive] + config.helpers[:active]
90
- else
91
- raise UnknownHelperContext.new_with_message(
92
- context: context
93
- )
94
- end
95
- end
96
-
97
- # @api private
98
- def included_helper_context(object)
99
- @__included_helpers.each_pair do |object_with_helpers, context|
100
- return context if object.is_a?(object_with_helpers)
101
- end
102
-
103
- nil
104
- end
105
- end
106
- end
107
- end
108
- end
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
- require "pakyow/support/inflector"
5
-
6
- module Pakyow
7
- module Behavior
8
- # Helps manage isolated classes for an app.
9
- #
10
- module Isolating
11
- extend Support::Extension
12
-
13
- class_methods do
14
- # Creates a subclass within the app's namespace.
15
- #
16
- # @example
17
- # class MyApp < Pakyow::App
18
- # isolate Pakyow::Controller do
19
- # def self.special_behavior
20
- # puts "it works"
21
- # end
22
- # end
23
- # end
24
- #
25
- # MyApp::Controller.special_behavior
26
- # => it works
27
- #
28
- # Pakyow::Controller
29
- # => NoMethodError (undefined method `special_behavior' for Pakyow::Controller:Class)
30
- #
31
- def isolate(class_to_isolate, &block)
32
- isolated_class_name = Support.inflector.demodulize(class_to_isolate.to_s).to_sym
33
-
34
- unless const_defined?(isolated_class_name, false)
35
- const_set(isolated_class_name, Class.new(class_to_isolate))
36
- end
37
-
38
- isolated(isolated_class_name).tap do |defined_subclass|
39
- defined_subclass.class_eval(&block) if block_given?
40
- end
41
- end
42
-
43
- # Returns true if the class name is isolated.
44
- #
45
- def isolated?(class_name)
46
- const_defined?(class_name)
47
- end
48
-
49
- # Returns the isolated class, evaluating the block (if provided).
50
- #
51
- def isolated(class_name, &block)
52
- if isolated?(class_name)
53
- const_get(class_name).tap do |isolated_class|
54
- isolated_class.class_eval(&block) if block_given?
55
- end
56
- else
57
- nil
58
- end
59
- end
60
- end
61
-
62
- # Convenience method for +Pakyow::App::subclass+.
63
- #
64
- def isolated(*args, &block)
65
- self.class.isolated(*args, &block)
66
- end
67
- end
68
- end
69
- end
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- require "pakyow/operation"
6
-
7
- module Pakyow
8
- module Behavior
9
- # Adds support for operations.
10
- #
11
- module Operations
12
- class Lookup
13
- def initialize(operations:, app:)
14
- operations.each do |operation|
15
- define_singleton_method operation.__object_name.name do |values = {}, &block|
16
- (block ? Class.new(operation, &block) : operation).new(app: app, **values).perform
17
- end
18
- end
19
- end
20
- end
21
-
22
- extend Support::Extension
23
-
24
- apply_extension do
25
- on "load" do
26
- load_aspect(:operations)
27
- end
28
-
29
- attr_reader :operations
30
- after "initialize" do
31
- @operations = Lookup.new(operations: state(:operation), app: self)
32
- end
33
- end
34
-
35
- class_methods do
36
- # Define operations as stateful when an app is defined.
37
- #
38
- # @api private
39
- def make(*)
40
- super.tap do |new_class|
41
- new_class.stateful :operation, Operation
42
- end
43
- end
44
- end
45
- end
46
- end
47
- end
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- module Pakyow
6
- module Behavior
7
- # Loads default pipeline actions based on included frameworks.
8
- #
9
- module Pipeline
10
- extend Support::Extension
11
-
12
- apply_extension do
13
- # We set the priority very low here in case initialize hooks in other frameworks define
14
- # state that should be loaded into the pipeline (e.g. controllers).
15
- #
16
- after "initialize", "initialize.pipeline", priority: -10 do
17
- self.class.__pipeline.dup.tap do |pipeline|
18
- load_pipeline_defaults(pipeline)
19
- @__pipeline = pipeline.callable(self)
20
- end
21
- end
22
- end
23
-
24
- private
25
-
26
- def load_pipeline_defaults(pipeline)
27
- if self.class.includes_framework?(:assets)
28
- pipeline.action(Actions::Assets::Public, self)
29
- pipeline.action(Actions::Assets::Process)
30
- end
31
-
32
- if self.class.includes_framework?(:realtime) && Pakyow.config.realtime.server && !is_a?(Plugin)
33
- pipeline.action(Actions::Realtime::Upgrader)
34
- end
35
-
36
- if self.class.includes_framework?(:routing) && !Pakyow.env?(:prototype)
37
- state(:controller).each do |controller|
38
- pipeline.action(controller, self)
39
- end
40
- end
41
-
42
- if instance_variable_defined?(:@plugs)
43
- @plugs.each do |plug_instance|
44
- pipeline.action(plug_instance)
45
- end
46
- end
47
-
48
- if self.class.includes_framework?(:presenter)
49
- pipeline.action(Actions::Presenter::AutoRender)
50
- end
51
-
52
- if self.class.includes_framework?(:routing) && !Pakyow.env?(:prototype) && !is_a?(Plugin)
53
- pipeline.action(Actions::Routing::RespondMissing)
54
- end
55
- end
56
- end
57
- end
58
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- module Pakyow
6
- module Behavior
7
- # Lets an app to be rescued from errors encountered during boot. Once rescued,
8
- # an app returns a 500 response with the error that caused it to fail.
9
- #
10
- module Rescuing
11
- extend Support::Extension
12
-
13
- # Error the app was rescued from.
14
- #
15
- attr_reader :rescued
16
-
17
- # Returns true if the app has been rescued.
18
- #
19
- def rescued?
20
- instance_variable_defined?(:@rescued) && !!@rescued
21
- end
22
-
23
- private
24
-
25
- # Enters rescue mode after logging the error.
26
- #
27
- def rescue!(error)
28
- @rescued = error
29
-
30
- performing :rescue do
31
- Pakyow.logger.error(error)
32
-
33
- message = <<~ERROR
34
- #{self.class} failed to initialize.
35
-
36
- #{error.message}
37
- #{error.backtrace.join("\n")}
38
- ERROR
39
-
40
- # Override call to always return an errored response.
41
- #
42
- define_singleton_method :call do |connection|
43
- connection.status = 500
44
- connection.body = StringIO.new(message)
45
- connection.halt
46
- end
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
- require "pakyow/support/inflector"
5
-
6
- module Pakyow
7
- module Behavior
8
- module Sessions
9
- extend Support::Extension
10
-
11
- apply_extension do
12
- attr_reader :session_object, :session_options
13
-
14
- after "configure" do
15
- if config.session.enabled
16
- require "pakyow/app/connection/session/#{config.session.object}"
17
-
18
- @session_object = Pakyow::App::Connection::Session.const_get(
19
- Support.inflector.classify(config.session.object)
20
- )
21
-
22
- @session_options = if config.session.respond_to?(config.session.object)
23
- config.session.public_send(config.session.object)
24
- else
25
- {}
26
- end
27
- end
28
- rescue LoadError => error
29
- # TODO: Improve this with a specific "session object missing" error.
30
- #
31
- raise error
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,172 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- require "pakyow/logger/formatters/human"
6
- require "pakyow/logger/formatters/logfmt"
7
-
8
- module Pakyow
9
- module Environment
10
- module Behavior
11
- module Config
12
- extend Support::Extension
13
-
14
- apply_extension do
15
- setting :default_env, :development
16
- setting :freeze_on_boot, true
17
- setting :exit_on_boot_failure, true
18
- setting :timezone, :utc
19
- setting :secrets, ["pakyow"]
20
-
21
- setting :connection_class do
22
- require "pakyow/connection"
23
- Connection
24
- end
25
-
26
- setting :root do
27
- File.expand_path(".")
28
- end
29
-
30
- setting :lib do
31
- File.join(config.root, "lib")
32
- end
33
-
34
- setting :environment_path do
35
- File.join(config.root, "config/environment")
36
- end
37
-
38
- setting :loader_path do
39
- File.join(config.root, "config/loader")
40
- end
41
-
42
- defaults :test do
43
- setting :exit_on_boot_failure, false
44
- end
45
-
46
- defaults :production do
47
- setting :secrets, [ENV["SECRET"].to_s.strip]
48
- end
49
-
50
- configurable :server do
51
- setting :host, "localhost"
52
- setting :port, 3000
53
- setting :count, 1
54
- setting :proxy, true
55
-
56
- defaults :production do
57
- setting :proxy, false
58
-
59
- setting :host do
60
- ENV["HOST"] || "0.0.0.0"
61
- end
62
-
63
- setting :port do
64
- ENV["PORT"] || 3000
65
- end
66
-
67
- setting :count do
68
- ENV["WORKERS"] || 5
69
- end
70
- end
71
- end
72
-
73
- configurable :cli do
74
- setting :repl do
75
- require "irb"; IRB
76
- end
77
- end
78
-
79
- configurable :logger do
80
- setting :enabled, true
81
- setting :sync, true
82
-
83
- setting :level do
84
- if config.logger.enabled
85
- :debug
86
- else
87
- :off
88
- end
89
- end
90
-
91
- setting :formatter do
92
- Logger::Formatters::Human
93
- end
94
-
95
- setting :destinations do
96
- if config.logger.enabled
97
- { stdout: $stdout }
98
- else
99
- {}
100
- end
101
- end
102
-
103
- defaults :test do
104
- setting :enabled, false
105
- end
106
-
107
- defaults :production do
108
- setting :level do
109
- if config.logger.enabled
110
- :info
111
- else
112
- :off
113
- end
114
- end
115
-
116
- setting :formatter do
117
- Logger::Formatters::Logfmt
118
- end
119
- end
120
-
121
- defaults :ludicrous do
122
- setting :enabled, false
123
- end
124
- end
125
-
126
- configurable :normalizer do
127
- setting :strict_path, true
128
- setting :strict_www, false
129
- setting :require_www, true
130
- end
131
-
132
- configurable :tasks do
133
- setting :paths, ["./tasks", File.expand_path("../../../tasks", __FILE__)]
134
- setting :prelaunch, []
135
- end
136
-
137
- configurable :redis do
138
- configurable :connection do
139
- setting :url do
140
- ENV["REDIS_URL"] || "redis://127.0.0.1:6379"
141
- end
142
-
143
- setting :timeout, 5
144
- setting :driver, nil
145
- setting :id, nil
146
- setting :tcp_keepalive, 5
147
- setting :reconnect_attempts, 1
148
- setting :inherit_socket, false
149
- end
150
-
151
- configurable :pool do
152
- setting :size, 3
153
- setting :timeout, 1
154
- end
155
-
156
- setting :key_prefix, "pw"
157
- end
158
-
159
- configurable :cookies do
160
- setting :domain
161
- setting :path, "/"
162
- setting :max_age
163
- setting :expires
164
- setting :secure
165
- setting :http_only
166
- setting :same_site
167
- end
168
- end
169
- end
170
- end
171
- end
172
- end