Class: AccessControlEntry
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AccessControlEntry
- Defined in:
- app/models/access_control_entry.rb
Class Method Summary collapse
Instance Method Summary collapse
- #able_options ⇒ Object
- #configure(ability) ⇒ Object
- #method_name ⇒ Object
- #options ⇒ Object
- #options_str ⇒ Object
- #options_str=(str) ⇒ Object
- #resource ⇒ Object
- #resource=(res) ⇒ Object
- #resource_class ⇒ Object
- #role=(role) ⇒ Object
- #user_email ⇒ Object
- #user_email=(email) ⇒ Object
Class Method Details
.can(verb, resource, options = {}) ⇒ Object
77 78 79 |
# File 'app/models/access_control_entry.rb', line 77 def self.can(verb, resource, ={}) AccessControlEntry.new(:can=>true, :verb=> verb, :resource=>resource, :options=> ) end |
.cannot(verb, resource, options) ⇒ Object
80 81 82 |
# File 'app/models/access_control_entry.rb', line 80 def self.cannot(verb, resource, ) AccessControlEntry.new(:can=>false, :verb=> verb, :resource=>resource, :options=> ) end |
Instance Method Details
#able_options ⇒ Object
69 70 71 72 73 74 75 |
# File 'app/models/access_control_entry.rb', line 69 def if resource.is_a?(ActiveRecord::Base) .merge({:id=>resource.id}) else end end |
#configure(ability) ⇒ Object
63 64 65 66 67 |
# File 'app/models/access_control_entry.rb', line 63 def configure(ability) raise "I only like Ability" unless ability.class==Ability able = self.can ? :can : :cannot ability.send able, verb.to_sym, resource_type.try(:constantize), end |
#method_name ⇒ Object
84 85 86 |
# File 'app/models/access_control_entry.rb', line 84 def method_name self.can ? :can : :cannot end |
#options ⇒ Object
42 43 44 |
# File 'app/models/access_control_entry.rb', line 42 def @options ||= (self. ? eval(self.) : {}) end |
#options_str ⇒ Object
46 47 48 |
# File 'app/models/access_control_entry.rb', line 46 def .map{|u,v| "#{u.inspect}=>#{v.is_numeric? ? v : v.inspect}"}.join(", ") end |
#options_str=(str) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/access_control_entry.rb', line 49 def (str) opts = str.split(",").map(&:strip).map_hash{|keyval| key, val = keyval.split("=>").map(&:strip) val = val.to_i if val.is_numeric? if key.index(":") key = key.gsub(/\:/, "").to_sym end {key=>val} } @options = opts self. = opts.inspect end |
#resource ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/access_control_entry.rb', line 29 def resource unless @res if resource_id @res = resource_type.constantize.find(resource_id) unless resource_type.empty? else @res = resource_type.constantize unless resource_type.empty? end end @res end |
#resource=(res) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'app/models/access_control_entry.rb', line 20 def resource=(res) @res = res if res.is_a? Class then self.resource_type = res.name else self.resource_id = res.id self.resource_type = res.class.name end end |
#resource_class ⇒ Object
40 |
# File 'app/models/access_control_entry.rb', line 40 def resource_class; resource_type.constantize unless resource_type.empty?; end |
#role=(role) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'app/models/access_control_entry.rb', line 95 def role=(role) if role.kind_of? Role self.role_id = role.id else role = role.to_s.camelize self.role_id = (role.is_numeric? ? role : Role.find_by_name(role).id) unless role.empty? end end |
#user_email ⇒ Object
88 89 90 |
# File 'app/models/access_control_entry.rb', line 88 def user_email self.user.email if self.user end |
#user_email=(email) ⇒ Object
91 92 93 |
# File 'app/models/access_control_entry.rb', line 91 def user_email=(email) self.user = User.find_by_email(email) unless email.blank? end |