validatable_associations 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +12 -2
- data/VERSION +1 -1
- data/lib/validatable_associations.rb +11 -11
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -1,12 +1,22 @@
|
|
1
1
|
= ValidatableAssociations
|
2
2
|
|
3
|
-
ValidatableAssociations is
|
3
|
+
ValidatableAssociations is a Rails plugin and add-on to Jay Fields
|
4
4
|
{Validatable}[http://validatable.rubyforge.org] library. This add-on lets you
|
5
|
-
specify associations to other validatable
|
5
|
+
specify associations to other validatable Classes and allows you to set up a
|
6
6
|
decent validatable structure.
|
7
7
|
|
8
8
|
== Install
|
9
9
|
|
10
|
+
Install the gem (recommended):
|
11
|
+
|
12
|
+
$ gem install validatable_associations
|
13
|
+
|
14
|
+
Please notice that the validatable_associations gem is in the
|
15
|
+
{gemcutter}[http://gemcutter.org] repository. Please follow the instructions
|
16
|
+
provided on their website to set up your rubygems installation.
|
17
|
+
|
18
|
+
Or install as a Rails plugin:
|
19
|
+
|
10
20
|
$ script/plugin install git://github.com/rubiii/validatable_associations.git
|
11
21
|
|
12
22
|
== Associations
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# == ValidatableAssociations
|
2
|
-
#
|
3
|
-
# ValidatableAssociations is
|
4
|
-
#
|
5
|
-
#
|
2
|
+
#
|
3
|
+
# ValidatableAssociations is a Rails plugin and add-on to Jay Fields Validatable
|
4
|
+
# library. This add-on lets you specify associations to other validatable Classes
|
5
|
+
# and allows you to set up a decent validatable structure.
|
6
6
|
module ValidatableAssociations
|
7
7
|
|
8
8
|
# ValidatableAssociations::ClassMethods
|
9
9
|
#
|
10
|
-
# Includes
|
10
|
+
# Includes Class methods for setting up the associations.
|
11
11
|
module ClassMethods
|
12
12
|
|
13
13
|
# Reader/writer method for has_one associations. Sets 1-n +associations+
|
@@ -16,7 +16,7 @@ module ValidatableAssociations
|
|
16
16
|
def has_one(*associations)
|
17
17
|
@has_one = [] unless @has_one
|
18
18
|
return @has_one if associations.empty?
|
19
|
-
@has_one
|
19
|
+
@has_one += associations.map { |association| association.to_s }
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
@@ -36,7 +36,7 @@ module ValidatableAssociations
|
|
36
36
|
# a reader/writer method of an association and handles the read/write process.
|
37
37
|
# Delegates to super otherwise.
|
38
38
|
def method_missing(method, *args)
|
39
|
-
association_name =
|
39
|
+
association_name = association_name_from(method)
|
40
40
|
super unless self.class.has_one.include? association_name
|
41
41
|
|
42
42
|
association_to_set = find_or_create_association(association_name, args[0])
|
@@ -77,10 +77,10 @@ private
|
|
77
77
|
# initialized already or in case of given +arguments+.
|
78
78
|
def find_or_create_association(association_name, arguments = nil)
|
79
79
|
if arguments
|
80
|
-
|
80
|
+
constant_from(association_name).new arguments
|
81
81
|
else
|
82
82
|
association = self.instance_variable_get("@#{association_name}")
|
83
|
-
association =
|
83
|
+
association = constant_from(association_name).new unless association
|
84
84
|
association
|
85
85
|
end
|
86
86
|
end
|
@@ -100,7 +100,7 @@ private
|
|
100
100
|
|
101
101
|
# Expects the name of a reader/writer +method+ and turns it into a valid
|
102
102
|
# name for an association.
|
103
|
-
def
|
103
|
+
def association_name_from(method)
|
104
104
|
association_name = method.to_s
|
105
105
|
association_name.slice!(-1) if association_name[-1, 1] == "="
|
106
106
|
association_name
|
@@ -109,7 +109,7 @@ private
|
|
109
109
|
# Converts a given +symbol+ from snake_case into an existing Constant.
|
110
110
|
# Note that the constanize method might raise a NameError in case the given
|
111
111
|
# symbol could not be mapped to a Constant.
|
112
|
-
def
|
112
|
+
def constant_from(symbol)
|
113
113
|
symbol.to_s.camelize.constantize
|
114
114
|
end
|
115
115
|
|