module Pakyow::Application::Behavior::Helpers
Maintains a list of helper modules, with code for including helpers of a type into an object.
Helpers
are either global, passive, or active. Global helpers contain utility methods or methods that need application-level state. Passive helpers can access state on the connection but never change connection state, which active helpers are solely responsible for doing.
Public Instance Methods
helpers(context)
click to toggle source
# File lib/pakyow/application/behavior/helpers.rb, line 80 def helpers(context) case context.to_sym when :global config.helpers[:global] when :passive config.helpers[:global] + config.helpers[:passive] when :active config.helpers[:global] + config.helpers[:passive] + config.helpers[:active] else raise UnknownHelperContext.new_with_message( context: context ) end end
include_helpers(context, object)
click to toggle source
Includes helpers of a particular context into an object. Global helpers will automatically be included into active and passive contexts, and passive helpers will automatically be included into the active context.
# File lib/pakyow/application/behavior/helpers.rb, line 72 def include_helpers(context, object) @__included_helpers[object] = context helpers(context.to_sym).each do |helper| object.include helper end end
included_helper_context(object)
click to toggle source
@api private
# File lib/pakyow/application/behavior/helpers.rb, line 96 def included_helper_context(object) @__included_helpers.each_pair do |object_with_helpers, context| return context if object.is_a?(object_with_helpers) end nil end
register_helper(context, helper_module)
click to toggle source
Registers a helper module to be loaded on defined endpoints.
# File lib/pakyow/application/behavior/helpers.rb, line 64 def register_helper(context, helper_module) (config.helpers[context.to_sym] << helper_module).uniq! end