Module: ActsAsPermission::Permittable
- Defined in:
- lib/acts_as_permission.rb
Instance Method Summary collapse
- #create_default_permissions! ⇒ Object
- #create_permission!(route, value, ext = nil) ⇒ Object
- #has_permission?(action) ⇒ Boolean
- #permission(route, ext = nil) ⇒ Object
- #permission?(route, ext = nil) ⇒ Boolean
Instance Method Details
#create_default_permissions! ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/acts_as_permission.rb', line 33 def = self.class..map do |route, masks| masks.map do |mask| ext = mask.dup value = ext.delete(:value) (route, value, ext) end end .flatten! .compact end |
#create_permission!(route, value, ext = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/acts_as_permission.rb', line 20 def (route, value, ext = nil) return unless self.class.permittable?(route) ext = { :permitted_type => (ext.blank? ? nil : ext.class.name), :permitted_id => (ext.blank? ? nil : ext.id) } unless ext.is_a? Hash context = {:route => route}.merge(ext) parameters = context.merge(:value => value) .create(parameters) unless .exists?(context) end |
#has_permission?(action) ⇒ Boolean
47 48 49 50 51 52 53 |
# File 'lib/acts_as_permission.rb', line 47 def (action) ActiveSupport::Deprecation.warn 'has_permission?(action) is deprecated ' + 'and may be removed from future releases, use permission?(route, ext ' + '= nil) instead.' [self.class.name.tableize, action].join('#') end |
#permission(route, ext = nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/acts_as_permission.rb', line 3 def (route, ext = nil) ext = { :permitted_type => (ext.blank? ? nil : ext.class.name), :permitted_id => (ext.blank? ? nil : ext.id) } unless ext.is_a? Hash context = {:route => route}.merge(ext) (route, ext) unless .exists?(context) .first(:conditions => context) end |
#permission?(route, ext = nil) ⇒ Boolean
15 16 17 18 |
# File 'lib/acts_as_permission.rb', line 15 def (route, ext = nil) = (route, ext) .value? if .present? end |