pakyow-core 1.0.0.rc5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b04af7b325d0cc914fdfd8fd532d3ae22d118121c97c2f368af0b661412f120
4
- data.tar.gz: a0ad74d7cf6d0b7f83badf14b4048d66f26f52fa0e1208388f6027528f92c80a
3
+ metadata.gz: b05dfdf492076f0324c4bb0e1567f96c180672f9dd86fb038fdd350bcf4844fe
4
+ data.tar.gz: bff7b800c753d8b417b22412ac5334e6f6984f55296bb004761ccf83d927d1b2
5
5
  SHA512:
6
- metadata.gz: 79447f22d448507b3ca69ea4b34288a03dd89895379c1c60c42b41adddedac530138e87622216fcd3c68f89b0369a42b1dfb7a8fcc0fe0c068d7db7772ed12fd
7
- data.tar.gz: 8915e4739ee5c1dcdacd54aaf8214b9940fcb6449ec345356d5d3e9742ddfc8a487b787f224943e1d6ace467ad3dcf98db19608b472764d5d78ccf07e143d23c
6
+ metadata.gz: af3cfb3710fa7552a6d1defefb2158c2b82d57adc4da6e5e7bdb2ed1d66492a04ffda19a3cb9b13ce17adff6e7991536d493b1615b1d3c26c57049c5331f5a5d
7
+ data.tar.gz: 423e1fe954bbd6e102a1b477b27fe37f8840f51e7bb35b1598a47426300c487ef56cd90b63e22e294f11432c623550c93219eb8a1f2d71f0a7b8a39765daac01
data/CHANGELOG.md CHANGED
@@ -0,0 +1,5 @@
1
+ # UNRELEASED
2
+
3
+ # 1.0
4
+
5
+ * Hello, Web
@@ -8,19 +8,19 @@ require "pakyow/support/hookable"
8
8
  require "pakyow/support/configurable"
9
9
  require "pakyow/support/pipeline"
10
10
 
11
- require "pakyow/behavior/config"
12
- require "pakyow/behavior/sessions"
13
- require "pakyow/behavior/endpoints"
14
- require "pakyow/behavior/pipeline"
15
- require "pakyow/behavior/frameworks"
16
- require "pakyow/behavior/aspects"
17
- require "pakyow/behavior/helpers"
18
- require "pakyow/behavior/rescuing"
19
- require "pakyow/behavior/restarting"
20
- require "pakyow/behavior/isolating"
21
- require "pakyow/behavior/initializers"
22
- require "pakyow/behavior/plugins"
23
- require "pakyow/behavior/operations"
11
+ require "pakyow/application/config"
12
+ require "pakyow/application/behavior/sessions"
13
+ require "pakyow/application/behavior/endpoints"
14
+ require "pakyow/application/behavior/pipeline"
15
+ require "pakyow/application/behavior/frameworks"
16
+ require "pakyow/application/behavior/aspects"
17
+ require "pakyow/application/behavior/helpers"
18
+ require "pakyow/application/behavior/rescuing"
19
+ require "pakyow/application/behavior/restarting"
20
+ require "pakyow/application/behavior/isolating"
21
+ require "pakyow/application/behavior/initializers"
22
+ require "pakyow/application/behavior/plugins"
23
+ require "pakyow/application/behavior/operations"
24
24
 
25
25
  require "pakyow/connection"
26
26
 
@@ -29,11 +29,11 @@ module Pakyow
29
29
  # create multiple application objects, each containing its own state. These
30
30
  # applications can then be mounted as an endpoint within the environment.
31
31
  #
32
- # Pakyow::App.define do
32
+ # Pakyow::Application.define do
33
33
  # # state shared between all apps goes here
34
34
  # end
35
35
  #
36
- # class API < Pakyow::App
36
+ # class API < Pakyow::Application
37
37
  # # state for this app goes here
38
38
  # end
39
39
  #
@@ -43,7 +43,7 @@ module Pakyow
43
43
  #
44
44
  # = Pipeline
45
45
  #
46
- # Requests are received by {App#call}, creating a {Connection} object that
46
+ # Requests are received by {Application#call}, creating a {Connection} object that
47
47
  # provides an interface to the underlying request state. The connection is
48
48
  # pushed through a pipeline. Each pipeline action can modify the connection
49
49
  # and then either 1) allow the connection to hit the next action 2) halt
@@ -53,28 +53,28 @@ module Pakyow
53
53
  # halted, the connection is finalized and returned, otherwise app assumes
54
54
  # that the connection was unhandled and returns a canned 404 response.
55
55
  #
56
- # App also catches any unhandled errors that occur in the pipeline by simply
56
+ # Application also catches any unhandled errors that occur in the pipeline by simply
57
57
  # logging the error and returning a canned 500 response.
58
58
  #
59
59
  # @see Support::Pipeline
60
60
  #
61
61
  # = Configuration
62
62
  #
63
- # App objects can be configured.
63
+ # Application objects can be configured.
64
64
  #
65
- # Pakyow::App.configure do
65
+ # Pakyow::Application.configure do
66
66
  # config.name = "my-app"
67
67
  # end
68
68
  #
69
69
  # It's possible to configure for certain environments.
70
70
  #
71
- # Pakyow::App.configure :development do
71
+ # Pakyow::Application.configure :development do
72
72
  # config.name = "my-dev-app"
73
73
  # end
74
74
  #
75
75
  # The +app+ config namespace can be extended with your own custom options.
76
76
  #
77
- # Pakyow::App.configure do
77
+ # Pakyow::Application.configure do
78
78
  # config.foo = "bar"
79
79
  # end
80
80
  #
@@ -94,14 +94,14 @@ module Pakyow
94
94
  #
95
95
  # Here's how to log a message after initialize:
96
96
  #
97
- # Pakyow::App.after "initialize" do
97
+ # Pakyow::Application.after "initialize" do
98
98
  # logger.info "initialized #{self}"
99
99
  # end
100
100
  #
101
101
  # @see Support::Hookable
102
102
  #
103
- class App
104
- require "pakyow/app/connection"
103
+ class Application
104
+ require "pakyow/application/connection"
105
105
 
106
106
  class << self
107
107
  def inherited(subclass)
@@ -117,7 +117,7 @@ module Pakyow
117
117
  #
118
118
  attr_reader :environment
119
119
 
120
- # App mount path.
120
+ # Application mount path.
121
121
  #
122
122
  attr_reader :mount_path
123
123
 
@@ -131,7 +131,7 @@ module Pakyow
131
131
  include Support::Definable
132
132
  include Support::Pipeline
133
133
 
134
- include Behavior::Config
134
+ include Config
135
135
  include Behavior::Sessions
136
136
  include Behavior::Endpoints
137
137
  include Behavior::Pipeline
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pakyow/support/extension"
4
+
5
+ require "pakyow/loader"
6
+
7
+ module Pakyow
8
+ class Application
9
+ module Behavior
10
+ # Maintains known aspects and loads them.
11
+ #
12
+ module Aspects
13
+ extend Support::Extension
14
+
15
+ apply_extension do
16
+ setting :aspects, []
17
+
18
+ after "load" do
19
+ config.aspects.each do |aspect|
20
+ load_aspect(aspect)
21
+ end
22
+ end
23
+ end
24
+
25
+ class_methods do
26
+ # Registers an app aspect by name.
27
+ #
28
+ def aspect(name)
29
+ (config.aspects << name.to_sym).uniq!
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def load_aspect(aspect, path: File.join(config.src, aspect.to_s), target: self.class)
36
+ __load_aspect(aspect, path: path, target: target)
37
+ end
38
+
39
+ def __load_aspect(aspect, path: File.join(config.src, aspect.to_s), target: self.class)
40
+ Dir.glob(File.join(path, "*.rb")) do |file_path|
41
+ Loader.new(file_path).call(target)
42
+ end
43
+
44
+ Dir.glob(File.join(path, "*")).select { |sub_path| File.directory?(sub_path) }.each do |directory|
45
+ __load_aspect(aspect, path: directory, target: target)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pakyow/support/extension"
4
+
5
+ require "pakyow/endpoints"
6
+
7
+ module Pakyow
8
+ class Application
9
+ module Behavior
10
+ module Endpoints
11
+ extend Support::Extension
12
+
13
+ apply_extension do
14
+ after "initialize" do
15
+ load_endpoints
16
+ end
17
+ end
18
+
19
+ prepend_methods do
20
+ def initialize(*)
21
+ @endpoints = ::Pakyow::Endpoints.new
22
+
23
+ super
24
+ end
25
+ end
26
+
27
+ # Instance of {Endpoints} for path building.
28
+ #
29
+ attr_reader :endpoints
30
+
31
+ private
32
+
33
+ def load_endpoints
34
+ state.values.each do |state_object|
35
+ state_object.instances.each do |state_instance|
36
+ @endpoints.load(state_instance)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pakyow/support/extension"
4
+
5
+ module Pakyow
6
+ class Application
7
+ module Behavior
8
+ # Manages {Framework} instances.
9
+ #
10
+ module Frameworks
11
+ extend Support::Extension
12
+
13
+ apply_extension do
14
+ setting :loaded_frameworks, []
15
+ end
16
+
17
+ class_methods do
18
+ # Includes one or more frameworks into the app class.
19
+ #
20
+ def include_frameworks(*frameworks)
21
+ tap do
22
+ frameworks.each do |framework_name|
23
+ include_framework(framework_name)
24
+ end
25
+ end
26
+ end
27
+
28
+ # Includes a framework into the app class.
29
+ #
30
+ def include_framework(framework_name)
31
+ framework_name = framework_name.to_sym
32
+ Pakyow.frameworks.fetch(framework_name).new(self).boot
33
+ (config.loaded_frameworks << framework_name).uniq!
34
+ rescue KeyError => error
35
+ raise UnknownFramework.build(error, framework: framework_name)
36
+ end
37
+
38
+ # Returns true if +framework+ is loaded.
39
+ #
40
+ def includes_framework?(framework_name)
41
+ config.loaded_frameworks.include?(framework_name.to_sym)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pakyow/support/extension"
4
+ require "pakyow/support/safe_string"
5
+
6
+ require "pakyow/helper"
7
+
8
+ require "pakyow/application/helpers/app"
9
+ require "pakyow/application/helpers/connection"
10
+
11
+ module Pakyow
12
+ class Application
13
+ module Behavior
14
+ # Maintains a list of helper modules, with code for including helpers of a type into an object.
15
+ #
16
+ # Helpers are either global, passive, or active. Global helpers contain utility methods or
17
+ # methods that need application-level state. Passive helpers can access state on the connection
18
+ # but never change connection state, which active helpers are solely responsible for doing.
19
+ #
20
+ module Helpers
21
+ extend Support::Extension
22
+
23
+ apply_extension do
24
+ class_state :__included_helpers, default: {}, inheritable: true
25
+
26
+ setting :helpers,
27
+ global: [
28
+ Pakyow::Application::Helpers::Application,
29
+ Support::SafeStringHelpers
30
+ ],
31
+
32
+ passive: [
33
+ Pakyow::Application::Helpers::Connection
34
+ ],
35
+
36
+ active: []
37
+
38
+ on "load" do
39
+ # Helpers are loaded first so that other aspects inherit them.
40
+ #
41
+ load_aspect(:helpers)
42
+
43
+ self.class.state(:helper).each do |helper|
44
+ context = if helper.instance_variable_defined?(:@type)
45
+ helper.instance_variable_get(:@type)
46
+ else
47
+ :global
48
+ end
49
+
50
+ self.class.register_helper(context, helper)
51
+ end
52
+ end
53
+
54
+ # Define helpers as stateful after an app is made.
55
+ #
56
+ after "make", priority: :high do
57
+ stateful :helper, Helper
58
+ end
59
+ end
60
+
61
+ class_methods do
62
+ # Registers a helper module to be loaded on defined endpoints.
63
+ #
64
+ def register_helper(context, helper_module)
65
+ (config.helpers[context.to_sym] << helper_module).uniq!
66
+ end
67
+
68
+ # Includes helpers of a particular context into an object. Global helpers
69
+ # will automatically be included into active and passive contexts, and
70
+ # passive helpers will automatically be included into the active context.
71
+ #
72
+ def include_helpers(context, object)
73
+ @__included_helpers[object] = context
74
+
75
+ helpers(context.to_sym).each do |helper|
76
+ object.include helper
77
+ end
78
+ end
79
+
80
+ def helpers(context)
81
+ case context.to_sym
82
+ when :global
83
+ config.helpers[:global]
84
+ when :passive
85
+ config.helpers[:global] + config.helpers[:passive]
86
+ when :active
87
+ config.helpers[:global] + config.helpers[:passive] + config.helpers[:active]
88
+ else
89
+ raise UnknownHelperContext.new_with_message(
90
+ context: context
91
+ )
92
+ end
93
+ end
94
+
95
+ # @api private
96
+ def included_helper_context(object)
97
+ @__included_helpers.each_pair do |object_with_helpers, context|
98
+ return context if object.is_a?(object_with_helpers)
99
+ end
100
+
101
+ nil
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
@@ -3,15 +3,15 @@
3
3
  require "pakyow/support/extension"
4
4
 
5
5
  module Pakyow
6
- module Environment
6
+ class Application
7
7
  module Behavior
8
8
  module Initializers
9
9
  extend Support::Extension
10
10
 
11
11
  apply_extension do
12
- on "configure" do
13
- Dir.glob(File.join(Pakyow.config.root, "config/initializers/environment/**/*.rb")).each do |initializer|
14
- require initializer
12
+ after "make" do
13
+ Dir.glob(File.join(config.root, "config/initializers/application/**/*.rb")).each do |initializer|
14
+ class_eval(File.read(initializer), initializer)
15
15
  end
16
16
  end
17
17
  end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pakyow/support/extension"
4
+ require "pakyow/support/inflector"
5
+
6
+ module Pakyow
7
+ class Application
8
+ module Behavior
9
+ # Helps manage isolated classes for an app.
10
+ #
11
+ module Isolating
12
+ extend Support::Extension
13
+
14
+ class_methods do
15
+ # Creates a subclass within the app's namespace.
16
+ #
17
+ # @example
18
+ # class MyApplication < Pakyow::Application
19
+ # isolate Pakyow::Controller do
20
+ # def self.special_behavior
21
+ # puts "it works"
22
+ # end
23
+ # end
24
+ # end
25
+ #
26
+ # MyApplication::Controller.special_behavior
27
+ # => it works
28
+ #
29
+ # Pakyow::Controller
30
+ # => NoMethodError (undefined method `special_behavior' for Pakyow::Controller:Class)
31
+ #
32
+ def isolate(class_to_isolate, &block)
33
+ isolated_class_name = Support.inflector.demodulize(class_to_isolate.to_s).to_sym
34
+
35
+ unless const_defined?(isolated_class_name, false)
36
+ const_set(isolated_class_name, Class.new(class_to_isolate))
37
+ end
38
+
39
+ isolated(isolated_class_name).tap do |defined_subclass|
40
+ defined_subclass.class_eval(&block) if block_given?
41
+ end
42
+ end
43
+
44
+ # Returns true if the class name is isolated.
45
+ #
46
+ def isolated?(class_name)
47
+ const_defined?(class_name)
48
+ end
49
+
50
+ # Returns the isolated class, evaluating the block (if provided).
51
+ #
52
+ def isolated(class_name, &block)
53
+ if isolated?(class_name)
54
+ const_get(class_name).tap do |isolated_class|
55
+ isolated_class.class_eval(&block) if block_given?
56
+ end
57
+ else
58
+ nil
59
+ end
60
+ end
61
+ end
62
+
63
+ # Convenience method for +Pakyow::Application::subclass+.
64
+ #
65
+ def isolated(*args, &block)
66
+ self.class.isolated(*args, &block)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end