Class: Pakyow::Plugin Private
- Inherits:
-
Object
- Object
- Pakyow::Plugin
- Extended by:
- Support::ClassState
- Includes:
- Application::Behavior::Aspects, Application::Behavior::Endpoints, Application::Behavior::Frameworks, Application::Behavior::Helpers, Application::Behavior::Isolating, Application::Behavior::Operations, Application::Behavior::Pipeline, Application::Behavior::Rescuing, Application::Behavior::Restarting, Support::Configurable, Support::Definable, Support::Hookable, Support::Pipeline
- Defined in:
- lib/pakyow/plugin.rb,
lib/pakyow/plugin/state.rb,
lib/pakyow/plugin/lookup.rb,
lib/pakyow/plugin/helper_caller.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Base plugin class.
Defined Under Namespace
Classes: HelperCaller, Lookup, State
Class Attribute Summary collapse
- .mount_path ⇒ Object readonly private
- .plugin_name ⇒ Object readonly private
- .plugin_path ⇒ Object readonly private
Instance Attribute Summary collapse
- #parent ⇒ Object readonly private
Attributes included from Application::Behavior::Rescuing
Attributes included from Application::Behavior::Endpoints
Class Method Summary collapse
- ._load(state) ⇒ Object private
- .disable(*features) ⇒ Object private
- .enable(*features) ⇒ Object private
- .features ⇒ Object private
-
.inherited(plugin_class) ⇒ Object
private
rubocop:enabled Naming/MethodName.
-
.Plugin(name, path) ⇒ Object
private
rubocop:disable Naming/MethodName.
Instance Method Summary collapse
- #__object_name ⇒ Object private
- #_dump(_) ⇒ Object private
- #booted ⇒ Object private
- #call(connection) ⇒ Object private
- #exposed_value_name(name) ⇒ Object private
- #feature?(name) ⇒ Boolean private
- #frontend_key(name = nil) ⇒ Object private
- #helper_caller(helper_context, connection, call_context) ⇒ Object private
- #helpers(connection) ⇒ Object private
-
#initialize(parent, &block) ⇒ Plugin
constructor
private
A new instance of Plugin.
- #load_frontend ⇒ Object private
- #method_missing(method_name, *args, &block) ⇒ Object private
- #plugin_path ⇒ Object private
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean private
- #top ⇒ Object private
Methods included from Application::Behavior::Restarting
Methods included from Application::Behavior::Rescuing
Methods included from Application::Behavior::Isolating
Constructor Details
#initialize(parent, &block) ⇒ Plugin
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Plugin.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/pakyow/plugin.rb', line 77 def initialize(parent, &block) super() @parent = parent @state = [] @endpoints = Endpoints.new @features = self.class.features @key = build_key performing :configure do configure!(@parent.environment) end performing :initialize do if block_given? instance_exec(&block) end # Load state prior to calling the load hooks so that helpers are available. # load_state # We still want to call the load hooks so that behavior works properly. # performing :load do; end defined! end create_helper_contexts if respond_to?(:boot) boot end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
128 129 130 131 132 133 134 |
# File 'lib/pakyow/plugin.rb', line 128 def method_missing(method_name, *args, &block) if @parent.respond_to?(method_name) @parent.public_send(method_name, *args, &block) else super end end |
Class Attribute Details
.mount_path ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
316 317 318 |
# File 'lib/pakyow/plugin.rb', line 316 def mount_path @mount_path end |
.plugin_name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
316 317 318 |
# File 'lib/pakyow/plugin.rb', line 316 def plugin_name @plugin_name end |
.plugin_path ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
316 317 318 |
# File 'lib/pakyow/plugin.rb', line 316 def plugin_path @plugin_path end |
Instance Attribute Details
#parent ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
75 76 77 |
# File 'lib/pakyow/plugin.rb', line 75 def parent @parent end |
Class Method Details
._load(state) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
193 194 195 196 197 198 199 200 |
# File 'lib/pakyow/plugin.rb', line 193 def self._load(state) state = Marshal.load(state) Pakyow.app(state[:parent][:name]).plugs.find { |plug| plug.class.plugin_name == state[:plugin_name] && plug.class.plugin_path == state[:plugin_path] && plug.class.mount_path == state[:mount_path] } end |
.disable(*features) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
344 345 346 |
# File 'lib/pakyow/plugin.rb', line 344 def disable(*features) @__disabled_features.concat(features) end |
.enable(*features) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
340 341 342 |
# File 'lib/pakyow/plugin.rb', line 340 def enable(*features) @__enabled_features.concat(features) end |
.features ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/pakyow/plugin.rb', line 348 def features Dir.glob(File.join(plugin_path, "features", "*")).map { |feature_path| { name: File.basename(feature_path).to_sym, path: feature_path } }.tap do |features| features.delete_if do |feature| @__disabled_features.include?(feature[:name]) end if @__enabled_features.any? features.keep_if do |feature| @__enabled_features.include?(feature[:name]) end end end end |
.inherited(plugin_class) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
rubocop:enabled Naming/MethodName
327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/pakyow/plugin.rb', line 327 def inherited(plugin_class) super if instance_variable_defined?(:@plugin_name) plugin_class.instance_variable_set(:@plugin_name, instance_variable_get(:@plugin_name)) plugin_class.instance_variable_set(:@plugin_path, instance_variable_get(:@plugin_path)) unless Pakyow.plugins.include?(@plugin_name) Pakyow.register_plugin(@plugin_name, plugin_class) end end end |
.Plugin(name, path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
rubocop:disable Naming/MethodName
319 320 321 322 323 324 |
# File 'lib/pakyow/plugin.rb', line 319 def Plugin(name, path) Class.new(self) do @plugin_name = name @plugin_path = path end end |
Instance Method Details
#__object_name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
145 146 147 |
# File 'lib/pakyow/plugin.rb', line 145 def __object_name self.class.__object_name end |
#_dump(_) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/pakyow/plugin.rb', line 178 def _dump(_) Marshal.dump( { parent: { name: @parent.config.name }, plugin_name: self.class.plugin_name, plugin_path: self.class.plugin_path, mount_path: self.class.mount_path } ) end |
#booted ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
113 114 115 |
# File 'lib/pakyow/plugin.rb', line 113 def booted call_hooks :after, :boot end |
#call(connection) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
124 125 126 |
# File 'lib/pakyow/plugin.rb', line 124 def call(connection) super(isolated(:Connection).from_connection(connection, :@app => self)) end |
#exposed_value_name(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
167 168 169 170 171 172 173 174 175 |
# File 'lib/pakyow/plugin.rb', line 167 def exposed_value_name(name) prefix = if self.class.__object_name.name == :default self.class.plugin_name else "#{self.class.plugin_name}(#{self.class.__object_name.name})" end :"__#{prefix}.#{name}" end |
#feature?(name) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
117 118 119 120 121 122 |
# File 'lib/pakyow/plugin.rb', line 117 def feature?(name) name = name.to_sym @features.any? { |feature| feature[:name] == name } end |
#frontend_key(name = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
202 203 204 205 206 207 208 |
# File 'lib/pakyow/plugin.rb', line 202 def frontend_key(name = nil) if name :"@#{@key}.#{name}" else @key end end |
#helper_caller(helper_context, connection, call_context) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
153 154 155 156 157 158 159 160 161 |
# File 'lib/pakyow/plugin.rb', line 153 def helper_caller(helper_context, connection, call_context) connection = connection.class.from_connection(connection, :@app => self) HelperCaller.new( plugin: self, connection: connection, helpers: @helper_contexts[helper_context.to_sym].new(connection, call_context) ) end |
#helpers(connection) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
140 141 142 |
# File 'lib/pakyow/plugin.rb', line 140 def helpers(connection) @helper_class.new(self, connection) end |
#load_frontend ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
163 164 165 |
# File 'lib/pakyow/plugin.rb', line 163 def load_frontend @state.each(&:load_frontend) end |
#plugin_path ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
149 150 151 |
# File 'lib/pakyow/plugin.rb', line 149 def plugin_path self.class.plugin_path end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
136 137 138 |
# File 'lib/pakyow/plugin.rb', line 136 def respond_to_missing?(method_name, include_private = false) @parent.respond_to?(method_name) || super end |
#top ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
210 211 212 |
# File 'lib/pakyow/plugin.rb', line 210 def top parent.top end |