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.
@@ -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(name) do
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(name) do
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{spring-fu}
3
- s.version = "0.1.3"
3
+ s.version = "0.1.4"
4
4
 
5
5
  s.specification_version = 2 if s.respond_to? :specification_version=
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mszczytowski-spring-fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Szczytowski