Module: RulesEngine::ControllerUsers::ClassMethods

Defined in:
lib/rules_engine/controller_users.rb

Instance Method Summary collapse

Instance Method Details

#can_signup=(can_signup) ⇒ Object



105
106
107
# File 'lib/rules_engine/controller_users.rb', line 105

def can_signup=()
  @can_signup = 
end

#can_signup?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/rules_engine/controller_users.rb', line 109

def can_signup?
  @can_signup || false
end

#define_access_level(name, access_level) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/rules_engine/controller_users.rb', line 78

def define_access_level name, access_level
  (class << self; self end).instance_eval do
    USER_ACCESS_LEVEL << [name.to_s.titleize, access_level]
  end
  
  (class << self; self end).instance_eval do
    define_method "#{name}_access_level" do
      access_level
    end      
  end
  
  define_method "#{name}?" do
    logged_in? && current_user.access_level >= access_level
  end

  define_method "#{name}_access_required" do
    
    return unless logged_in?
    unless current_user.access_level >= access_level
      flash[:error]="This page requires #{name} access"
      user_access_denied
    end
  end
  
  self.send :helper_method, "#{name}?"
end