91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/acts_as_permission.rb', line 91
def self.acts_as_permission(acl)
@acl = acl.to_a.inject({}) do |list, permission|
route, masks = permission.to_a[0], permission.to_a[1]
masks = [masks] unless masks.is_a?(Array)
permission = {:value => masks.first}
permission.freeze
extensions = masks[1] || []
extensions = [extensions] unless extensions.is_a?(Array)
extensions.map! do |ext|
ext ||= {}
ext.freeze
end
permissions = extensions.unshift(permission)
permissions.compact!
permissions.uniq!
permissions.freeze
list.update({route.to_sym => permissions})
end
@acl.freeze
has_many :permissions, :as => :permittable, :dependent => :destroy
accepts_nested_attributes_for :permissions, :allow_destroy => true
attr_accessible :permissions_attributes
validates_associated :permissions
class << self
def permittable?(route)
@acl.has_key?(route.to_sym)
end
def permissions
@acl
end
end
include ActsAsPermission::Permittable
end
|