Module: Maromi::Helpers::SmartAuthorizerMarshal
- Included in:
- Authorization, Request
- Defined in:
- lib/maromi/helpers/smart_authorizer_marshal.rb
Overview
A little helper for storing authorizers on requests and authorizations that knows how to deal with AR and DM objects
Instance Method Summary collapse
-
#authorizer ⇒ Object
Intelligently plucks objects stored using SAM.authorizer=(obj).
-
#authorizer=(obj) ⇒ Object
Sets Datamapper attributes properly in the case that obj is an AR or DM object.
Instance Method Details
#authorizer ⇒ Object
Intelligently plucks objects stored using SAM.authorizer=(obj).
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/maromi/helpers/smart_authorizer_marshal.rb', line 24 def , klass = attribute_get(:authorizer), attribute_get(:authorizer_class) return nil if .nil? return if = Marshal.load(attribute_get(:authorizer)) and ( klass.nil? || klass == '' ) if defined? ActiveRecord and (klass = eval(klass)).ancestors.include? ActiveRecord::Base return klass.find() else return klass.get!() end end |
#authorizer=(obj) ⇒ Object
Sets Datamapper attributes properly in the case that obj is an AR or DM object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/maromi/helpers/smart_authorizer_marshal.rb', line 9 def (obj) if defined? ActiveRecord and obj.is_a? ActiveRecord::Base attribute_set(:authorizer, Marshal.dump(obj.send(obj.class.primary_key))) attribute_set(:authorizer_class, obj.class) return obj elsif obj.class.included_modules.include? DataMapper::Resource attribute_set(:authorizer, Marshal.dump(obj.key[0])) attribute_set(:authorizer_class, obj.class) else attribute_set(:authorizer, Marshal.dump(obj)) end end |