Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add public API for class -> method name transformations.

  • Loading branch information...
commit 2fd1d26a0c7fdd66077647ceb7329f6a3af44942 1 parent 3840cfe
@jbarnette authored
Showing with 9 additions and 6 deletions.
  1. +9 −6 lib/modelizer.rb
View
15 lib/modelizer.rb
@@ -28,9 +28,13 @@ def self.included target
target.extend Modelizer::Validations
end
- @@namespace = true
- def self.namespace?; @@namespace end
- def self.namespace= ns; @@namespace = ns end
+ def self.method_name_for model_class
+ underscore model_class.name
+ end
+
+ def self.model_class_for test_class
+ test_class.name.gsub(/Test$/, "").constantize
+ end
def self.underscore classname
classname.gsub(/::/, '_').
@@ -65,9 +69,8 @@ def model_template_for klass, defaults = {}, &block
::Modelizer.cache[klass] = [defaults, block]
- klass = klass.name
- nsklass = Modelizer.namespace? ? klass : klass.split("::").last
- model = ::Modelizer.underscore nsklass
+ model = ::Modelizer.method_name_for klass
+ klass = klass.name
module_eval <<-END, __FILE__, __LINE__ + 1
def valid_#{model}_attributes extras = {}
Please sign in to comment.
Something went wrong with that request. Please try again.