assignable_values 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -55,6 +55,10 @@ You can access the humanized version for the current value like this:
|
|
55
55
|
song = Song.new(:genre => 'pop')
|
56
56
|
song.humanized_genre # => 'Pop music'
|
57
57
|
|
58
|
+
Or you can retrieve the humanized version of any given value by passing it as an argument:
|
59
|
+
|
60
|
+
song.humanized_genre('rock') # => 'Rock music'
|
61
|
+
|
58
62
|
When obtaining a list of assignable values, each value will have a method `#humanized` that returns the translation:
|
59
63
|
|
60
64
|
song.assignable_genres.first # => "pop"
|
@@ -33,8 +33,9 @@ module AssignableValues
|
|
33
33
|
def define_humanized_method
|
34
34
|
restriction = self
|
35
35
|
enhance_model do
|
36
|
-
define_method "humanized_#{restriction.property}" do
|
37
|
-
|
36
|
+
define_method "humanized_#{restriction.property}" do |*args|
|
37
|
+
given_value = args[0]
|
38
|
+
value = given_value || send(restriction.property)
|
38
39
|
restriction.humanize_string_value(value)
|
39
40
|
end
|
40
41
|
end
|
@@ -71,6 +71,11 @@ describe AssignableValues::ActiveRecord do
|
|
71
71
|
song.humanized_genre.should be_nil
|
72
72
|
end
|
73
73
|
|
74
|
+
it 'should generate a method to retrieve the humanization of any given value' do
|
75
|
+
song = @klass.new(:genre => 'pop')
|
76
|
+
song.humanized_genre('rock').should == 'Rock music'
|
77
|
+
end
|
78
|
+
|
74
79
|
end
|
75
80
|
|
76
81
|
context 'if the :allow_blank option is set' do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assignable_values
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Henning Koch
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-07-
|
18
|
+
date: 2012-07-31 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|