lib/ki/modules/restrictions.rb in ki-0.4.4 vs lib/ki/modules/restrictions.rb in ki-0.4.5

- old
+ new

@@ -4,47 +4,40 @@ def forbidden_actions [] end def forbid *actions - send :define_method, :forbidden_actions do - actions - end - - eigen_class = class << self; self; end - eigen_class.send(:define_method, :forbidden_actions) do - actions - end + generic_restriction :forbidden_actions, actions end def required_attributes [] end def requires *attributes - send :define_method, :required_attributes do - attributes - end - - eigen_class = class << self; self; end - eigen_class.send(:define_method, :required_attributes) do - attributes - end + generic_restriction :required_attributes, attributes end def unique_attributes [] end def unique *attributes - send :define_method, :unique_attributes do + generic_restriction :unique_attributes, attributes + end + + private + + def generic_restriction method_name, attributes + send :define_method, method_name do attributes end eigen_class = class << self; self; end - eigen_class.send(:define_method, :unique_attributes) do + eigen_class.send(:define_method, method_name) do attributes end end + end end end