module IAmMe

Public Instance Methods

me() click to toggle source
# File lib/i-am-me.rb, line 29
def me
  RequestStore[:me]
end
Also aliased as: my
me_is_a(type_of_me) click to toggle source
# File lib/i-am-me.rb, line 11
def me_is_a(type_of_me)
  @type_of_me = type_of_me
end
my()
Alias for: me
set_me() click to toggle source
# File lib/i-am-me.rb, line 16
def set_me
  # before_actionフックによりset_meメソッドがコールされるコントローラは`me_is_a`メソッドがコールされたコントローラと同じとは限らないため、
  # ancestorsを遡ってtype_of_meを探す。
  type_of_me = nil
  self.class.ancestors.each do |ancestor|
    type_of_me = ancestor.instance_variable_get(:@type_of_me)
    break if type_of_me
    break if ancestor == ApplicationController
  end
  return unless respond_to?("current_#{type_of_me}")
  RequestStore[:me] = send("current_#{type_of_me}")
end