Sha256: dadff3d3a33c2c6689c66dadf005f3e57bc789c4ac42dcde8480c3057302d590
Contents?: true
Size: 1.26 KB
Versions: 1
Compression:
Stored size: 1.26 KB
Contents
module SudoAttributes module Base def sudo_attr_protected(*attrs) Private::set_attributes(self, attrs, :protected) end def sudo_attr_accessible(*attrs) Private::set_attributes(self, attrs, :accessible) end end module Private def self.set_attributes(klass, attrs, type) unless attrs.empty? raise "Invalid argument passed to has_sudo_attributes" unless attrs.all? {|a| a.is_a? Symbol } klass.send("attr_#{type}", *attrs) end klass.extend SudoAttributes::ClassMethods klass.send :include, SudoAttributes::InstanceMethods end end # Added to ActiveRecord model only if has_sudo_attributes is called module ClassMethods def sudo_create(attributes=nil) instance = sudo_new(attributes) instance.save instance end def sudo_create!(attributes=nil) instance = sudo_new(attributes) instance.save! instance end def sudo_new(attributes=nil) instance = new(nil) instance.send(:attributes=, attributes, false) instance end end module InstanceMethods def sudo_update_attributes(new_attributes) self.send(:attributes=, new_attributes, false) save end end end ActiveRecord::Base.extend SudoAttributes::Base
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sudo_attributes-0.4.0 | lib/sudo_attributes.rb |