Sha256: 23863880e90040a14b74b856fffa2754ca5bb15b25f8b6899a3ea84461ff1a74

Contents?: true

Size: 1006 Bytes

Versions: 7

Compression:

Stored size: 1006 Bytes

Contents

module C2
  module ControllerAdditions        
    def self.included(base)
      base.extend ClassMethods
      base.helper_method :current_c2_agent, :current_c2_agent_title, :c2_login_path, :c2_profile_path, :c2_logout_path
    end
    
    module ClassMethods
      def current_c2_agent
        @current_c2_agent ||= current_user
      end
    
      def current_c2_agent_title
        @current_c2_agent_title ||= current_c2_agent.send(([:c2_title, :title, :name, :email].map(&:to_s) & current_c2_agent.methods).first)
      end
    
      def c2_clearance?
        current_c2_agent && current_c2_agent.admin?
      end
    
      def authorize_c2_agent
        raise C2::AccessDenied unless c2_clearance?
      end
    
      def c2_login_path
        '/'
      end
    
      def c2_profile_path
        '/'
      end
    
      def c2_logout_path
        '/'
      end
    end
  end
end

if defined? ActionController
  ActionController::Base.class_eval do
    include C2::ControllerAdditions
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
c2-0.1.13 lib/c2/controller_additions.rb
c2-0.1.12 lib/c2/controller_additions.rb
c2-0.1.11 lib/c2/controller_additions.rb
c2-0.1.10 lib/c2/controller_additions.rb
c2-0.1.9 lib/c2/controller_additions.rb
c2-0.1.8 lib/c2/controller_additions.rb
c2-0.1.7 lib/c2/controller_additions.rb