lib/contexts.rb in contexts-1.0.0 vs lib/contexts.rb in contexts-1.1.0

- old
+ new

@@ -1,16 +1,34 @@ require 'contexts/version' require 'mapper' module Contexts + def self.resolve(name) + if name.is_a?(Class) + name.new + else + "#{name}_context".classify.constantize.new + end + end + def self.included(base) base.class_eval do + extend ClassMethods + before_action :apply_contexts helper_method :contexts, :current_context, :locked_context, :context_locked? + end + end + + module ClassMethods + def preload_contexts(*names) + prepend_before_action do + names.each{ |name| contexts[name] ||= Contexts.resolve(name) } + end end end def contexts @contexts ||= (request.env['contexts'] || {})