Sha256: a4f31ed1585dbb6ec5b7dd81b9c661b0223f336b6c2be7bd21ee478c983e3bf0
Contents?: true
Size: 1.33 KB
Versions: 2
Compression:
Stored size: 1.33 KB
Contents
module Janus # A collection of abstraction helper methods used in Janus controllers and views. # This should be of no particular outside of abstract controllers for Janus that # must be working for all scopes at once. module InternalHelpers extend ActiveSupport::Concern included do helper_method :janus_scope, :resource, :resource_class, :resource_name end # Abstract method for the authenticate_scope! before filter, with scope # as detected by janus_scope. def authenticate! send("authenticate_#{janus_scope}!") end # Detects the scope from the controller name. def janus_scope @janus_scope ||= self.class.name.split('::', 2).first.underscore.singularize end # Returns the `@user` instance variable (or `@admin` or whatever), # as detected by janus_scope. def resource instance_variable_get(:"@#{janus_scope}") end # Sets the `@user` instance variable (or `@admin` or whatever), # as detected by janus_scope. def resource=(value) instance_variable_set(:"@#{janus_scope}", value) end # Returns the `User` class (or `Admin` or whatever) as detected by janus_scope. def resource_class @resource_class ||= janus_scope.camelize.constantize end # Alias for janus_scope. def resource_name janus_scope end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
janus-0.7.0 | lib/janus/controllers/internal_helpers.rb |
janus-0.6.0 | lib/janus/controllers/internal_helpers.rb |