mszczytowski-spring-fu 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/maciej_szczytowski/spring_fu.rb +10 -3
- data/spring-fu.gemspec +1 -1
- metadata +1 -1
@@ -19,6 +19,8 @@ module MaciejSzczytowski
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
# Add accessor method returned Spring bean named +name+.
|
23
|
+
#
|
22
24
|
# Example:
|
23
25
|
#
|
24
26
|
# class YourController < ApplicationController
|
@@ -31,6 +33,11 @@ module MaciejSzczytowski
|
|
31
33
|
# end
|
32
34
|
# end
|
33
35
|
#
|
36
|
+
# Options are:
|
37
|
+
# * <tt>:as</tt> - Accessor method name, dafault is bean name.
|
38
|
+
# * <tt>:default</tt> - Value returned if bean can't be found in Spring context. Default is <tt>nil</tt>.
|
39
|
+
# * <tt>:allow_nil</tt> - By default, <tt>false</tt>, raise error if bean can't be found, otherwise return <tt>:default</tt> value. If <tt>:default</tt> is different than <tt>nil</tt>, <tt>:allow_nil</tt> is treated as <tt>true</tt>.
|
40
|
+
#
|
34
41
|
module ClassMethods
|
35
42
|
|
36
43
|
def spring_bean(name, options = {})
|
@@ -54,13 +61,13 @@ module MaciejSzczytowski
|
|
54
61
|
end
|
55
62
|
|
56
63
|
if bean_name
|
57
|
-
define_method(
|
64
|
+
define_method(options[:as]) do
|
58
65
|
self.class.send(:get_bean_from_spring_context, bean_name)
|
59
66
|
end
|
60
67
|
elsif options[:default] or options[:allow_nil]
|
61
68
|
# there is no bean with given name, return default value
|
62
69
|
# when default is not nil, allow_nil options is not significant
|
63
|
-
define_method(
|
70
|
+
define_method(options[:as]) do
|
64
71
|
options[:default]
|
65
72
|
end
|
66
73
|
else
|
@@ -141,4 +148,4 @@ module MaciejSzczytowski
|
|
141
148
|
|
142
149
|
end
|
143
150
|
|
144
|
-
end
|
151
|
+
end
|
data/spring-fu.gemspec
CHANGED