ultra-max-sys 0.0.1
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.
Potentially problematic release.
This version of ultra-max-sys might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/roda-3.106.0/MIT-LICENSE +21 -0
- data/roda-3.106.0/lib/roda/cache.rb +42 -0
- data/roda-3.106.0/lib/roda/plugins/Integer_matcher_max.rb +55 -0
- data/roda-3.106.0/lib/roda/plugins/_after_hook.rb +11 -0
- data/roda-3.106.0/lib/roda/plugins/_base64.rb +34 -0
- data/roda-3.106.0/lib/roda/plugins/_before_hook.rb +41 -0
- data/roda-3.106.0/lib/roda/plugins/_optimized_matching.rb +227 -0
- data/roda-3.106.0/lib/roda/plugins/_symbol_class_matchers.rb +108 -0
- data/roda-3.106.0/lib/roda/plugins/_symbol_regexp_matchers.rb +24 -0
- data/roda-3.106.0/lib/roda/plugins/additional_render_engines.rb +61 -0
- data/roda-3.106.0/lib/roda/plugins/additional_view_directories.rb +66 -0
- data/roda-3.106.0/lib/roda/plugins/all_verbs.rb +50 -0
- data/roda-3.106.0/lib/roda/plugins/assets.rb +902 -0
- data/roda-3.106.0/lib/roda/plugins/assets_preloading.rb +89 -0
- data/roda-3.106.0/lib/roda/plugins/assume_ssl.rb +28 -0
- data/roda-3.106.0/lib/roda/plugins/autoload_hash_branches.rb +79 -0
- data/roda-3.106.0/lib/roda/plugins/autoload_named_routes.rb +65 -0
- data/roda-3.106.0/lib/roda/plugins/backtracking_array.rb +88 -0
- data/roda-3.106.0/lib/roda/plugins/bearer_token.rb +28 -0
- data/roda-3.106.0/lib/roda/plugins/branch_locals.rb +76 -0
- data/roda-3.106.0/lib/roda/plugins/break.rb +43 -0
- data/roda-3.106.0/lib/roda/plugins/caching.rb +206 -0
- data/roda-3.106.0/lib/roda/plugins/capture_erb.rb +94 -0
- data/roda-3.106.0/lib/roda/plugins/chunked.rb +333 -0
- data/roda-3.106.0/lib/roda/plugins/class_level_routing.rb +111 -0
- data/roda-3.106.0/lib/roda/plugins/class_matchers.rb +155 -0
- data/roda-3.106.0/lib/roda/plugins/common_logger.rb +82 -0
- data/roda-3.106.0/lib/roda/plugins/conditional_sessions.rb +67 -0
- data/roda-3.106.0/lib/roda/plugins/content_for.rb +105 -0
- data/roda-3.106.0/lib/roda/plugins/content_security_policy.rb +333 -0
- data/roda-3.106.0/lib/roda/plugins/cookie_flags.rb +157 -0
- data/roda-3.106.0/lib/roda/plugins/cookies.rb +51 -0
- data/roda-3.106.0/lib/roda/plugins/csrf.rb +81 -0
- data/roda-3.106.0/lib/roda/plugins/custom_block_results.rb +85 -0
- data/roda-3.106.0/lib/roda/plugins/custom_matchers.rb +89 -0
- data/roda-3.106.0/lib/roda/plugins/default_headers.rb +64 -0
- data/roda-3.106.0/lib/roda/plugins/default_status.rb +35 -0
- data/roda-3.106.0/lib/roda/plugins/delay_build.rb +18 -0
- data/roda-3.106.0/lib/roda/plugins/delegate.rb +77 -0
- data/roda-3.106.0/lib/roda/plugins/delete_empty_headers.rb +36 -0
- data/roda-3.106.0/lib/roda/plugins/direct_call.rb +38 -0
- data/roda-3.106.0/lib/roda/plugins/disallow_file_uploads.rb +38 -0
- data/roda-3.106.0/lib/roda/plugins/drop_body.rb +43 -0
- data/roda-3.106.0/lib/roda/plugins/each_part.rb +87 -0
- data/roda-3.106.0/lib/roda/plugins/early_hints.rb +25 -0
- data/roda-3.106.0/lib/roda/plugins/empty_root.rb +49 -0
- data/roda-3.106.0/lib/roda/plugins/environments.rb +79 -0
- data/roda-3.106.0/lib/roda/plugins/erb_h.rb +43 -0
- data/roda-3.106.0/lib/roda/plugins/error_email.rb +152 -0
- data/roda-3.106.0/lib/roda/plugins/error_handler.rb +133 -0
- data/roda-3.106.0/lib/roda/plugins/error_mail.rb +149 -0
- data/roda-3.106.0/lib/roda/plugins/exception_page.rb +445 -0
- data/roda-3.106.0/lib/roda/plugins/filter_common_logger.rb +46 -0
- data/roda-3.106.0/lib/roda/plugins/flash.rb +119 -0
- data/roda-3.106.0/lib/roda/plugins/h.rb +59 -0
- data/roda-3.106.0/lib/roda/plugins/halt.rb +108 -0
- data/roda-3.106.0/lib/roda/plugins/hash_branch_view_subdir.rb +76 -0
- data/roda-3.106.0/lib/roda/plugins/hash_branches.rb +145 -0
- data/roda-3.106.0/lib/roda/plugins/hash_matcher.rb +39 -0
- data/roda-3.106.0/lib/roda/plugins/hash_paths.rb +128 -0
- data/roda-3.106.0/lib/roda/plugins/hash_public.rb +125 -0
- data/roda-3.106.0/lib/roda/plugins/hash_public_cache.rb +91 -0
- data/roda-3.106.0/lib/roda/plugins/hash_routes.rb +304 -0
- data/roda-3.106.0/lib/roda/plugins/head.rb +99 -0
- data/roda-3.106.0/lib/roda/plugins/header_matchers.rb +88 -0
- data/roda-3.106.0/lib/roda/plugins/heartbeat.rb +41 -0
- data/roda-3.106.0/lib/roda/plugins/hmac_paths.rb +413 -0
- data/roda-3.106.0/lib/roda/plugins/hooks.rb +92 -0
- data/roda-3.106.0/lib/roda/plugins/host_authorization.rb +155 -0
- data/roda-3.106.0/lib/roda/plugins/host_routing.rb +194 -0
- data/roda-3.106.0/lib/roda/plugins/hsts.rb +35 -0
- data/roda-3.106.0/lib/roda/plugins/indifferent_params.rb +126 -0
- data/roda-3.106.0/lib/roda/plugins/inject_erb.rb +33 -0
- data/roda-3.106.0/lib/roda/plugins/invalid_request_body.rb +107 -0
- data/roda-3.106.0/lib/roda/plugins/ip_from_header.rb +34 -0
- data/roda-3.106.0/lib/roda/plugins/json.rb +119 -0
- data/roda-3.106.0/lib/roda/plugins/json_parser.rb +107 -0
- data/roda-3.106.0/lib/roda/plugins/link_to.rb +83 -0
- data/roda-3.106.0/lib/roda/plugins/mail_processor.rb +629 -0
- data/roda-3.106.0/lib/roda/plugins/mailer.rb +285 -0
- data/roda-3.106.0/lib/roda/plugins/map_matcher.rb +48 -0
- data/roda-3.106.0/lib/roda/plugins/match_affix.rb +64 -0
- data/roda-3.106.0/lib/roda/plugins/match_hook.rb +34 -0
- data/roda-3.106.0/lib/roda/plugins/match_hook_args.rb +93 -0
- data/roda-3.106.0/lib/roda/plugins/middleware.rb +225 -0
- data/roda-3.106.0/lib/roda/plugins/middleware_stack.rb +101 -0
- data/roda-3.106.0/lib/roda/plugins/module_include.rb +96 -0
- data/roda-3.106.0/lib/roda/plugins/multi_public.rb +95 -0
- data/roda-3.106.0/lib/roda/plugins/multi_route.rb +156 -0
- data/roda-3.106.0/lib/roda/plugins/multi_run.rb +144 -0
- data/roda-3.106.0/lib/roda/plugins/multi_view.rb +83 -0
- data/roda-3.106.0/lib/roda/plugins/multibyte_string_matcher.rb +57 -0
- data/roda-3.106.0/lib/roda/plugins/named_routes.rb +167 -0
- data/roda-3.106.0/lib/roda/plugins/named_templates.rb +102 -0
- data/roda-3.106.0/lib/roda/plugins/not_allowed.rb +151 -0
- data/roda-3.106.0/lib/roda/plugins/not_found.rb +55 -0
- data/roda-3.106.0/lib/roda/plugins/optimized_segment_matchers.rb +53 -0
- data/roda-3.106.0/lib/roda/plugins/optimized_string_matchers.rb +50 -0
- data/roda-3.106.0/lib/roda/plugins/padrino_render.rb +42 -0
- data/roda-3.106.0/lib/roda/plugins/param_matchers.rb +83 -0
- data/roda-3.106.0/lib/roda/plugins/params_capturing.rb +118 -0
- data/roda-3.106.0/lib/roda/plugins/part.rb +76 -0
- data/roda-3.106.0/lib/roda/plugins/partials.rb +74 -0
- data/roda-3.106.0/lib/roda/plugins/pass.rb +47 -0
- data/roda-3.106.0/lib/roda/plugins/path.rb +255 -0
- data/roda-3.106.0/lib/roda/plugins/path_matchers.rb +54 -0
- data/roda-3.106.0/lib/roda/plugins/path_rewriter.rb +111 -0
- data/roda-3.106.0/lib/roda/plugins/permissions_policy.rb +340 -0
- data/roda-3.106.0/lib/roda/plugins/placeholder_string_matchers.rb +48 -0
- data/roda-3.106.0/lib/roda/plugins/plain_hash_response_headers.rb +32 -0
- data/roda-3.106.0/lib/roda/plugins/precompile_templates.rb +156 -0
- data/roda-3.106.0/lib/roda/plugins/public.rb +182 -0
- data/roda-3.106.0/lib/roda/plugins/r.rb +35 -0
- data/roda-3.106.0/lib/roda/plugins/recheck_precompiled_assets.rb +107 -0
- data/roda-3.106.0/lib/roda/plugins/redirect_http_to_https.rb +99 -0
- data/roda-3.106.0/lib/roda/plugins/redirect_path.rb +59 -0
- data/roda-3.106.0/lib/roda/plugins/relative_path.rb +76 -0
- data/roda-3.106.0/lib/roda/plugins/render.rb +998 -0
- data/roda-3.106.0/lib/roda/plugins/render_coverage.rb +105 -0
- data/roda-3.106.0/lib/roda/plugins/render_each.rb +224 -0
- data/roda-3.106.0/lib/roda/plugins/render_locals.rb +102 -0
- data/roda-3.106.0/lib/roda/plugins/request_aref.rb +77 -0
- data/roda-3.106.0/lib/roda/plugins/request_headers.rb +83 -0
- data/roda-3.106.0/lib/roda/plugins/response_attachment.rb +94 -0
- data/roda-3.106.0/lib/roda/plugins/response_content_type.rb +79 -0
- data/roda-3.106.0/lib/roda/plugins/response_request.rb +36 -0
- data/roda-3.106.0/lib/roda/plugins/route_block_args.rb +50 -0
- data/roda-3.106.0/lib/roda/plugins/route_csrf.rb +388 -0
- data/roda-3.106.0/lib/roda/plugins/run_append_slash.rb +51 -0
- data/roda-3.106.0/lib/roda/plugins/run_handler.rb +51 -0
- data/roda-3.106.0/lib/roda/plugins/run_require_slash.rb +46 -0
- data/roda-3.106.0/lib/roda/plugins/sec_fetch_site_csrf.rb +131 -0
- data/roda-3.106.0/lib/roda/plugins/send_file.rb +127 -0
- data/roda-3.106.0/lib/roda/plugins/sessions.rb +537 -0
- data/roda-3.106.0/lib/roda/plugins/shape_friendly.rb +232 -0
- data/roda-3.106.0/lib/roda/plugins/shared_vars.rb +86 -0
- data/roda-3.106.0/lib/roda/plugins/sinatra_helpers.rb +444 -0
- data/roda-3.106.0/lib/roda/plugins/slash_path_empty.rb +26 -0
- data/roda-3.106.0/lib/roda/plugins/static.rb +42 -0
- data/roda-3.106.0/lib/roda/plugins/static_routing.rb +89 -0
- data/roda-3.106.0/lib/roda/plugins/status_303.rb +34 -0
- data/roda-3.106.0/lib/roda/plugins/status_handler.rb +86 -0
- data/roda-3.106.0/lib/roda/plugins/streaming.rb +170 -0
- data/roda-3.106.0/lib/roda/plugins/strip_path_prefix.rb +33 -0
- data/roda-3.106.0/lib/roda/plugins/symbol_matchers.rb +188 -0
- data/roda-3.106.0/lib/roda/plugins/symbol_status.rb +32 -0
- data/roda-3.106.0/lib/roda/plugins/symbol_views.rb +37 -0
- data/roda-3.106.0/lib/roda/plugins/timestamp_public.rb +78 -0
- data/roda-3.106.0/lib/roda/plugins/type_routing.rb +217 -0
- data/roda-3.106.0/lib/roda/plugins/typecast_params.rb +1185 -0
- data/roda-3.106.0/lib/roda/plugins/typecast_params_sized_integers.rb +108 -0
- data/roda-3.106.0/lib/roda/plugins/unescape_path.rb +41 -0
- data/roda-3.106.0/lib/roda/plugins/view_options.rb +203 -0
- data/roda-3.106.0/lib/roda/plugins/view_subdir_leading_slash.rb +49 -0
- data/roda-3.106.0/lib/roda/plugins.rb +68 -0
- data/roda-3.106.0/lib/roda/request.rb +722 -0
- data/roda-3.106.0/lib/roda/response.rb +221 -0
- data/roda-3.106.0/lib/roda/session_middleware.rb +184 -0
- data/roda-3.106.0/lib/roda/version.rb +18 -0
- data/roda-3.106.0/lib/roda.rb +741 -0
- data/ultra-max-sys.gemspec +12 -0
- metadata +202 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
class Roda
|
|
5
|
+
module RodaPlugins
|
|
6
|
+
# The shape_friendly plugin makes the scope, request, and response objects
|
|
7
|
+
# used by Roda friendly to object shapes, which can result in better
|
|
8
|
+
# performance on modern versions of Ruby, especially when the JIT compiler
|
|
9
|
+
# is enabled. All plugins shipped with Roda integrate with this plugin.
|
|
10
|
+
#
|
|
11
|
+
# In order for this behavior to be beneficial for your application, you
|
|
12
|
+
# need to either avoid setting instance variables inside your routing
|
|
13
|
+
# tree, or you need to register each instance variable used, to ensure
|
|
14
|
+
# that all instances have the same shape.
|
|
15
|
+
#
|
|
16
|
+
# If you want to avoid using instance variables in your routing tree, you
|
|
17
|
+
# can switch to using local variables. If using the render plugin, you can
|
|
18
|
+
# pass data from your routing tree to your views using the +:locals+ option.
|
|
19
|
+
# When passing data from your routing tree to other routing trees, such as
|
|
20
|
+
# when using the hash_branches plugin, you can use the shared_vars plugin,
|
|
21
|
+
# which stores the data in the Rack environment.
|
|
22
|
+
#
|
|
23
|
+
# To register instance variables set in your applications routing tree,
|
|
24
|
+
# use a +:scope_instance_variables+ option when loading the plugin,
|
|
25
|
+
# listing the instance variable symbols you are setting in the route
|
|
26
|
+
# block scope:
|
|
27
|
+
#
|
|
28
|
+
# class MyApp < Roda
|
|
29
|
+
# plugin :shape_friendly, scope_instance_variables: [:@var1, @:var2]
|
|
30
|
+
#
|
|
31
|
+
# route do |r|
|
|
32
|
+
# r.root do
|
|
33
|
+
# @var1 = "a"
|
|
34
|
+
# @var1.inspect
|
|
35
|
+
# end
|
|
36
|
+
#
|
|
37
|
+
# @var2 = "b"
|
|
38
|
+
# @var2.inspect
|
|
39
|
+
# end
|
|
40
|
+
# end
|
|
41
|
+
#
|
|
42
|
+
# When developing external plugins, you can set one of three constants in
|
|
43
|
+
# the plugin module to integrate with this plugin to support shape friendly
|
|
44
|
+
# behavior:
|
|
45
|
+
#
|
|
46
|
+
# * +SCOPE_INSTANCE_VARIABLES+: For instance variables set in +InstanceMethods+.
|
|
47
|
+
# * +REQUEST_INSTANCE_VARIABLES+: For instance variables set in +RequestMethods+.
|
|
48
|
+
# * +RESPONSE_INSTANCE_VARIABLES+: For instance variables set in +ResponseMethods+.
|
|
49
|
+
#
|
|
50
|
+
# These constants are set in the plugin module, not in the plugin's
|
|
51
|
+
# +InstanceMethods+, +RequestMethods+, or +ResponseMethods+ modules, to
|
|
52
|
+
# avoid pollution of the related namespaces in the class loading the plugin.
|
|
53
|
+
module ShapeFriendly
|
|
54
|
+
# This is used by the base support and not by this plugin.
|
|
55
|
+
RESPONSE_INSTANCE_VARIABLES = [:@status].freeze
|
|
56
|
+
|
|
57
|
+
# Set the Roda application to create the private
|
|
58
|
+
# _initialize_nil_instance_variables for the plugin to use.
|
|
59
|
+
def self.configure(app, opts=OPTS)
|
|
60
|
+
if scope_ivs = opts[:scope_instance_variables]
|
|
61
|
+
app.opts[:shape_friendly_scope_instance_variables] = Array(scope_ivs).dup.freeze
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
app.instance_exec do
|
|
65
|
+
def_initialize_nil_instance_variables(app, :SCOPE_INSTANCE_VARIABLES)
|
|
66
|
+
def_initialize_nil_instance_variables(app::RodaRequest, :REQUEST_INSTANCE_VARIABLES)
|
|
67
|
+
def_initialize_nil_instance_variables(app::RodaResponse, :RESPONSE_INSTANCE_VARIABLES)
|
|
68
|
+
|
|
69
|
+
# Avoid overhead of super call if possible
|
|
70
|
+
include(instance_method(:initialize).owner == Roda::RodaPlugins::Base::InstanceMethods ? OptimizedInstanceMethods : UnoptimizedInstanceMethods)
|
|
71
|
+
app::RodaRequest.send(:include, app::RodaRequest.instance_method(:initialize).owner == Roda::RodaPlugins::Base::RequestMethods ? OptimizedRequestMethods : UnoptimizedRequestMethods)
|
|
72
|
+
app::RodaResponse.send(:include, app::RodaResponse.instance_method(:initialize).owner == Roda::RodaPlugins::Base::ResponseMethods ? OptimizedResponseMethods : UnoptimizedResponseMethods)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
module ClassMethods
|
|
77
|
+
# Automatically refresh the instance variables used if the plugin
|
|
78
|
+
# sets instance variables.
|
|
79
|
+
def plugin(plugin, *args, &block)
|
|
80
|
+
super
|
|
81
|
+
plugin = RodaPlugins.load_plugin(plugin) if plugin.is_a?(Symbol)
|
|
82
|
+
[
|
|
83
|
+
[self, :SCOPE_INSTANCE_VARIABLES],
|
|
84
|
+
[self::RodaRequest, :REQUEST_INSTANCE_VARIABLES],
|
|
85
|
+
[self::RodaResponse, :RESPONSE_INSTANCE_VARIABLES],
|
|
86
|
+
].each do |klass, ivs_const|
|
|
87
|
+
if plugin.const_defined?(ivs_const)
|
|
88
|
+
def_initialize_nil_instance_variables(klass, ivs_const)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
nil
|
|
92
|
+
end
|
|
93
|
+
# :nocov:
|
|
94
|
+
ruby2_keywords(:plugin) if respond_to?(:ruby2_keywords, true)
|
|
95
|
+
# :nocov:
|
|
96
|
+
|
|
97
|
+
private
|
|
98
|
+
|
|
99
|
+
# If there are any intance variables configured in one of the plugins
|
|
100
|
+
# (looking for the +const+ constant in the plugin), override the
|
|
101
|
+
# private _initialize_nil_instance_variables method for the class,
|
|
102
|
+
# and have it initialize each instance variable to nil.
|
|
103
|
+
def def_initialize_nil_instance_variables(klass, const)
|
|
104
|
+
ivs = []
|
|
105
|
+
|
|
106
|
+
plugins.each do |mod|
|
|
107
|
+
ivs.concat(mod.const_get(const)) if mod.const_defined?(const)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
if const == :SCOPE_INSTANCE_VARIABLES && (scope_ivs = opts[:shape_friendly_scope_instance_variables])
|
|
111
|
+
ivs.concat(scope_ivs)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
ivs.each do |iv|
|
|
115
|
+
unless /\A@[a-z_][a-z0-9_]*\z/.match(iv)
|
|
116
|
+
raise RodaError, "invalid scope instance variable used"
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
unless ivs.empty?
|
|
121
|
+
ivs.uniq!
|
|
122
|
+
|
|
123
|
+
klass.class_eval(<<-RUBY, __FILE__, __LINE__+1)
|
|
124
|
+
def _initialize_nil_instance_variables
|
|
125
|
+
#{ivs.reverse.join(" = ")} = nil
|
|
126
|
+
end
|
|
127
|
+
private :_initialize_nil_instance_variables
|
|
128
|
+
alias _initialize_nil_instance_variables _initialize_nil_instance_variables
|
|
129
|
+
RUBY
|
|
130
|
+
nil
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# :nocov:
|
|
136
|
+
if RUBY_VERSION >= '4.0'
|
|
137
|
+
# :nocov:
|
|
138
|
+
module InstanceMethods
|
|
139
|
+
private
|
|
140
|
+
|
|
141
|
+
def instance_variables_to_inspect
|
|
142
|
+
instance_variables.reject{|v| instance_variable_get(v).nil?}
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
module OptimizedInstanceMethods
|
|
148
|
+
# Initialize configured instance variables to nil.
|
|
149
|
+
def initialize(env)
|
|
150
|
+
_initialize_nil_instance_variables
|
|
151
|
+
klass = self.class
|
|
152
|
+
@_request = klass::RodaRequest.new(self, env)
|
|
153
|
+
@_response = klass::RodaResponse.new
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
private
|
|
157
|
+
|
|
158
|
+
def _initialize_nil_instance_variables
|
|
159
|
+
nil
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
module UnoptimizedInstanceMethods
|
|
164
|
+
# Initialize configured instance variables to nil.
|
|
165
|
+
def initialize(env)
|
|
166
|
+
_initialize_nil_instance_variables
|
|
167
|
+
super
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
private
|
|
171
|
+
|
|
172
|
+
def _initialize_nil_instance_variables
|
|
173
|
+
nil
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
module OptimizedRequestMethods
|
|
178
|
+
# Initialize configured instance variables to nil.
|
|
179
|
+
def initialize(scope, env)
|
|
180
|
+
_initialize_nil_instance_variables
|
|
181
|
+
@scope = scope
|
|
182
|
+
@captures = []
|
|
183
|
+
@remaining_path = _remaining_path(env)
|
|
184
|
+
@env = env
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
private
|
|
188
|
+
|
|
189
|
+
def _initialize_nil_instance_variables
|
|
190
|
+
nil
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
module UnoptimizedRequestMethods
|
|
195
|
+
# Initialize configured instance variables to nil.
|
|
196
|
+
def initialize(scope, env)
|
|
197
|
+
_initialize_nil_instance_variables
|
|
198
|
+
super
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
private
|
|
202
|
+
|
|
203
|
+
def _initialize_nil_instance_variables
|
|
204
|
+
nil
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
module OptimizedResponseMethods
|
|
209
|
+
def initialize
|
|
210
|
+
_initialize_nil_instance_variables
|
|
211
|
+
@headers = _initialize_headers
|
|
212
|
+
@body = []
|
|
213
|
+
@length = 0
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
module UnoptimizedResponseMethods
|
|
218
|
+
# Initialize configured instance variables to nil.
|
|
219
|
+
def initialize
|
|
220
|
+
_initialize_nil_instance_variables
|
|
221
|
+
super
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
# For response methods, there is no default definition for
|
|
226
|
+
# _initialize_nil_instance_variables, as the plugin will always
|
|
227
|
+
# define a method in the class it is loaded into.
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
register_plugin(:shape_friendly, ShapeFriendly)
|
|
231
|
+
end
|
|
232
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
class Roda
|
|
5
|
+
module RodaPlugins
|
|
6
|
+
# The shared_vars plugin adds a +shared+ method for storing
|
|
7
|
+
# shared variables across nested Roda apps.
|
|
8
|
+
#
|
|
9
|
+
# class API < Roda
|
|
10
|
+
# plugin :shared_vars
|
|
11
|
+
# route do |r|
|
|
12
|
+
# user = shared[:user]
|
|
13
|
+
# # ...
|
|
14
|
+
# end
|
|
15
|
+
# end
|
|
16
|
+
#
|
|
17
|
+
# class App < Roda
|
|
18
|
+
# plugin :shared_vars
|
|
19
|
+
#
|
|
20
|
+
# route do |r|
|
|
21
|
+
# r.on Integer do |user_id|
|
|
22
|
+
# shared[:user] = User[user_id]
|
|
23
|
+
# r.run API
|
|
24
|
+
# end
|
|
25
|
+
# end
|
|
26
|
+
# end
|
|
27
|
+
#
|
|
28
|
+
# If you pass a hash to shared, it will update the shared
|
|
29
|
+
# vars with the content of the hash:
|
|
30
|
+
#
|
|
31
|
+
# route do |r|
|
|
32
|
+
# r.on Integer do |user_id|
|
|
33
|
+
# shared(user: User[user_id])
|
|
34
|
+
# r.run API
|
|
35
|
+
# end
|
|
36
|
+
# end
|
|
37
|
+
#
|
|
38
|
+
# You can also pass a block to shared, which will set the
|
|
39
|
+
# shared variables only for the given block, restoring the
|
|
40
|
+
# previous shared variables afterward:
|
|
41
|
+
#
|
|
42
|
+
# route do |r|
|
|
43
|
+
# r.on Integer do |user_id|
|
|
44
|
+
# shared(user: User[user_id]) do
|
|
45
|
+
# r.run API
|
|
46
|
+
# end
|
|
47
|
+
# end
|
|
48
|
+
# end
|
|
49
|
+
module SharedVars
|
|
50
|
+
module InstanceMethods
|
|
51
|
+
# Returns the current shared vars for the request. These are
|
|
52
|
+
# stored in the request's environment, so they will be implicitly
|
|
53
|
+
# shared with other apps using this plugin.
|
|
54
|
+
#
|
|
55
|
+
# If the +vars+ argument is given, it should be a hash that will be
|
|
56
|
+
# merged into the current shared vars.
|
|
57
|
+
#
|
|
58
|
+
# If a block is given, a +vars+ argument must be provided, and it will
|
|
59
|
+
# only make the changes to the shared vars for the duration of the
|
|
60
|
+
# block, restoring the previous shared vars before the block returns.
|
|
61
|
+
def shared(vars=nil)
|
|
62
|
+
h = env['roda.shared'] ||= {}
|
|
63
|
+
|
|
64
|
+
if defined?(yield)
|
|
65
|
+
if vars
|
|
66
|
+
begin
|
|
67
|
+
env['roda.shared'] = h.merge(vars)
|
|
68
|
+
yield
|
|
69
|
+
ensure
|
|
70
|
+
env['roda.shared'] = h
|
|
71
|
+
end
|
|
72
|
+
else
|
|
73
|
+
raise RodaError, "must pass a vars hash when calling shared with a block"
|
|
74
|
+
end
|
|
75
|
+
elsif vars
|
|
76
|
+
h.merge!(vars)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
h
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
register_plugin(:shared_vars, SharedVars)
|
|
85
|
+
end
|
|
86
|
+
end
|