Module: Cream::Helper::Role::Labels

Defined in:
lib/cream/helper/role.rb

Class Method Summary collapse

Class Method Details

.extract(options) ⇒ Object

Raises:

  • (ArgumentException)


134
135
136
137
138
139
140
141
142
143
144
# File 'lib/cream/helper/role.rb', line 134

def extract options
  case options
  when Symbol
    return :logged_in if logged_in_labels.include?(options)
    return :logged_out if logged_out_labels.include?(options)
  when Hash
    return :logged_in if logged_in_labels.any? {|lab| options[lab] }
    return :logged_out if logged_out_labels.any? {|lab| options[lab] }    
  end    
  raise ArgumentException, "Unknown option #{options}"
end

.is_guest?(current_user) ⇒ Boolean

Returns:

  • (Boolean)


162
163
164
# File 'lib/cream/helper/role.rb', line 162

def is_guest? current_user
  current_user && current_user.is?(:guest)
end

.is_not_guest?(current_user) ⇒ Boolean

Returns:

  • (Boolean)


158
159
160
# File 'lib/cream/helper/role.rb', line 158

def is_not_guest? current_user
  !current_user || (current_user && !current_user.is?(:guest))
end

.logged_in_check(state, current_user) ⇒ Object



150
151
152
# File 'lib/cream/helper/role.rb', line 150

def logged_in_check state, current_user
  state == :logged_in && is_not_guest?(current_user)
end

.logged_in_labelsObject



166
167
168
# File 'lib/cream/helper/role.rb', line 166

def logged_in_labels
  [:logged_in, :signed_in, :not_logged_out, :not_signed_out]
end

.logged_out_check(state, current_user) ⇒ Object



154
155
156
# File 'lib/cream/helper/role.rb', line 154

def logged_out_check state, current_user
  state == :logged_out && is_guest?(current_user)
end

.logged_out_labelsObject



170
171
172
# File 'lib/cream/helper/role.rb', line 170

def logged_out_labels
  [:logged_out, :signed_out, :not_logged_in, :not_signed_in]
end

.state_check(state, current_user) ⇒ Object



146
147
148
# File 'lib/cream/helper/role.rb', line 146

def state_check state, current_user
  logged_in_check(state, current_user) || logged_out_check(state, current_user)
end