Module: Amalgam::Authorities::Controllers::Helpers

Extended by:
ActiveSupport::Concern
Included in:
Amalgam::ApplicationController
Defined in:
lib/amalgam/authorities/controllers/helpers.rb

Class Method Summary collapse

Class Method Details

.amalgam_define_helpers(mapping, options = {}) ⇒ Object

:nodoc:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/amalgam/authorities/controllers/helpers.rb', line 12

def self.amalgam_define_helpers(mapping,options = {}) #:nodoc:

  as = options[:as].to_s if options[:as]

  class_eval "    def authenticate_\#{mapping}!\n      if !current_\#{mapping}\n        store_location\n        redirect_to \#{mapping}_signin_url, :alert => I18n.t('amalgam.sessions.fail.need_to_be_\#{mapping}')\n      end\n    end\n\n    def \#{mapping}_signed_in?\n      !!current_\#{mapping}\n    end\n\n    def current_\#{mapping}\n      @current_\#{mapping} ||= \#{mapping.classify.constantize}.find(session[:\#{mapping}_id]) if session[:\#{mapping}_id]\n    end\n\n  METHODS\n\n  if options[:as] && options[:as].to_s != mapping\n    class_eval <<-METHODS, __FILE__, __LINE__ + 1\n      def authenticate_\#{as}!\n        if !current_\#{as}\n          store_location\n          redirect_to \#{mapping}_signin_url, :alert => I18n.t('amalgam.sessions.fail.need_to_be_\#{as}')\n        end\n      end\n\n      def current_\#{as}\n        current_\#{mapping}\n      end\n\n      def \#{as}_signed_in?\n        !!current_\#{as}\n      end\n    METHODS\n  end\n\n  ActiveSupport.on_load(:action_controller) do\n    helper_method \"current_\#{mapping}\", \"\#{mapping}_signed_in?\"\n    helper_method \"current_\#{as}\", \"\#{as}_signed_in?\" if options[:as] && options[:as].to_s != mapping\n  end\nend\n", __FILE__, __LINE__ + 1