modelizer 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ === 3.0.0 / 2010-12-18
2
+
3
+ * Remove ill-advised namespace= introduced in 2.1.0.
4
+ * Add public API for class -> method name transformations.
5
+ * Remove assert_not_nil assumption.
6
+
1
7
  === 2.1.0 / 2010-12-18
2
8
 
3
9
  * Allow namespaces in helper names to be disabled.
@@ -4,7 +4,7 @@ require "modelizer/validations"
4
4
  module Modelizer
5
5
 
6
6
  # Duh.
7
- VERSION = "2.1.0"
7
+ VERSION = "3.0.0"
8
8
 
9
9
  include Modelizer::Assertions
10
10
 
@@ -28,9 +28,13 @@ module Modelizer
28
28
  target.extend Modelizer::Validations
29
29
  end
30
30
 
31
- @@namespace = true
32
- def self.namespace?; @@namespace end
33
- def self.namespace= ns; @@namespace = ns end
31
+ def self.method_name_for model_class
32
+ underscore model_class.name
33
+ end
34
+
35
+ def self.model_class_for test_class
36
+ test_class.name.gsub(/Test$/, "").constantize
37
+ end
34
38
 
35
39
  def self.underscore classname
36
40
  classname.gsub(/::/, '_').
@@ -65,9 +69,8 @@ module Modelizer
65
69
 
66
70
  ::Modelizer.cache[klass] = [defaults, block]
67
71
 
68
- klass = klass.name
69
- nsklass = Modelizer.namespace? ? klass : klass.split("::").last
70
- model = ::Modelizer.underscore nsklass
72
+ model = ::Modelizer.method_name_for klass
73
+ klass = klass.name
71
74
 
72
75
  module_eval <<-END, __FILE__, __LINE__ + 1
73
76
  def valid_#{model}_attributes extras = {}
@@ -1,8 +1,8 @@
1
1
  module Modelizer
2
2
  module Validations
3
3
  def test_validations_for attribute, *validations
4
- @klass ||= name.gsub(/Test$/, "").constantize
5
- @model ||= ::Modelizer.underscore @klass.name
4
+ @klass ||= ::Modelizer.model_class_for self
5
+ @model ||= ::Modelizer.method_name_for @klass
6
6
 
7
7
  unless instance_methods.collect { |m| m.to_s }.include? "new_#{@model}"
8
8
  raise "no model template for #{@klass.name}"
@@ -27,7 +27,7 @@ module Modelizer
27
27
  def validation_lambda_for_uniqueness klass, model, attribute
28
28
  lambda do
29
29
  existing = klass.first
30
- assert_not_nil existing, "There's at least one #{model} fixture."
30
+ assert existing, "There's at least one #{model} fixture."
31
31
 
32
32
  assert_invalid attribute,
33
33
  send("new_#{model}", attribute => existing.send(attribute))
metadata CHANGED
@@ -3,10 +3,10 @@ name: modelizer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
- - 2
7
- - 1
6
+ - 3
8
7
  - 0
9
- version: 2.1.0
8
+ - 0
9
+ version: 3.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Barnette