lib/sudo_attributes.rb in sudo_attributes-0.5.1 vs lib/sudo_attributes.rb in sudo_attributes-0.5.2
- old
+ new
@@ -25,20 +25,17 @@
def sudo_attr_accessible(*attrs)
Private::set_attributes(self, attrs, :accessible)
end
end
- module Private
+ module Private # :nodoc: all
# Used internally to assign protected attributes and include additional sudo_attributes functionality
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 }
+ # Call attr_(accessible|protected) if attributes are passed in
+ klass.send("attr_#{type}", *attrs) unless attrs.empty?
- klass.send("attr_#{type}", *attrs)
- end
-
klass.extend SudoAttributes::ClassMethods
klass.send :include, SudoAttributes::InstanceMethods
end
end
@@ -79,13 +76,11 @@
instance = new(nil)
instance.send(:attributes=, attributes, false)
instance
end
- # Alias of +sudo_new+
- def sudo_build(attributes=nil)
- sudo_new(attributes)
- end
+ alias sudo_build sudo_new
+
end
# Added to ActiveRecord model only if sudo_attr_(accessible|protected) is called
module InstanceMethods