Module: SocialStream::Controllers::Helpers
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/social_stream/controllers/helpers.rb
Overview
Common methods added to ApplicationController
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#current_ability ⇒ Object
Override Cancan#current_ability method to use #current_subject.
- #current_actor ⇒ Object
-
#current_subject ⇒ Object
Current subject represented by the user.
-
#current_subject=(instance) ⇒ Object
Set represented subject.
-
#profile_or_current_subject ⇒ Object
Returns the subject that is in the path, or the #current_subject if some User is logged in.
-
#profile_or_current_subject! ⇒ Object
This method tries #profile_or_current_subject but tries to authenticate if the user is not logged in.
-
#profile_subject ⇒ Object
Returns the subject that is in the path, or nil if it is not provided.
-
#profile_subject! ⇒ Object
Raise error if #profile_subject is not provided.
-
#profile_subject? ⇒ Boolean
Is #profile_subject provided?.
-
#profile_subject_is_current? ⇒ Boolean
A User must be logged in and is equal to #profile_subject.
Instance Method Details
#current_ability ⇒ Object
Override Cancan#current_ability method to use #current_subject
91 92 93 94 |
# File 'lib/social_stream/controllers/helpers.rb', line 91 def current_ability @current_ability ||= ::Ability.new(current_subject) end |
#current_actor ⇒ Object
40 41 42 |
# File 'lib/social_stream/controllers/helpers.rb', line 40 def current_actor current_subject.try(:actor) end |
#current_subject ⇒ Object
Current subject represented by the user. Defaults to the own user
25 26 27 28 29 30 |
# File 'lib/social_stream/controllers/helpers.rb', line 25 def current_subject @current_subject ||= current_subject_from_params || current_subject_from_session || current_user end |
#current_subject=(instance) ⇒ Object
Set represented subject
33 34 35 36 37 38 |
# File 'lib/social_stream/controllers/helpers.rb', line 33 def current_subject= instance session[:subject_type] = instance.class.to_s session[:subject_id] = instance.id @current_subject = instance end |
#profile_or_current_subject ⇒ Object
Returns the subject that is in the path, or the #current_subject if some User is logged in.
This method tries #profile_subject first and then #current_subject
75 76 77 |
# File 'lib/social_stream/controllers/helpers.rb', line 75 def profile_or_current_subject profile_subject || current_subject end |
#profile_or_current_subject! ⇒ Object
This method tries #profile_or_current_subject but tries to authenticate if the user is not logged in
81 82 83 |
# File 'lib/social_stream/controllers/helpers.rb', line 81 def profile_or_current_subject! profile_or_current_subject || warden.authenticate! end |
#profile_subject ⇒ Object
Returns the subject that is in the path, or nil if it is not provided
# /users/demo/posts
profile_subject #=> User demo
# /groups/test/posts
profile_subject #=> Group test
# /posts
profile_subject #=> nil
57 58 59 |
# File 'lib/social_stream/controllers/helpers.rb', line 57 def profile_subject @profile_subject ||= find_profile_subject end |
#profile_subject! ⇒ Object
Raise error if #profile_subject is not provided
67 68 69 |
# File 'lib/social_stream/controllers/helpers.rb', line 67 def profile_subject! profile_subject || warden.authenticate! end |
#profile_subject? ⇒ Boolean
Is #profile_subject provided?
62 63 64 |
# File 'lib/social_stream/controllers/helpers.rb', line 62 def profile_subject? profile_subject.present? end |
#profile_subject_is_current? ⇒ Boolean
A User must be logged in and is equal to #profile_subject
86 87 88 |
# File 'lib/social_stream/controllers/helpers.rb', line 86 def profile_subject_is_current? user_signed_in? && profile_subject == current_subject end |