assignable_values 0.15.0 → 0.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +2 -2
- data/gemfiles/Gemfile.2.3.lock +1 -1
- data/gemfiles/Gemfile.3.2.lock +1 -1
- data/gemfiles/Gemfile.4.2.lock +1 -1
- data/gemfiles/Gemfile.5.0.lock +1 -1
- data/gemfiles/Gemfile.5.1.lock +1 -1
- data/gemfiles/Gemfile.5.1.pg.lock +1 -1
- data/lib/assignable_values/active_record/restriction/scalar_attribute.rb +14 -1
- data/lib/assignable_values/version.rb +1 -1
- data/spec/assignable_values/active_record_spec.rb +30 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a7a9d96e5e738273b161df4a8cf85c5871122f909b6e50aad62fde7e7a21f14
|
4
|
+
data.tar.gz: 9b09dd1a6d0e1270876676442eeda26ca6f03650954b104efc9738aba80b0770
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c040fd853c739f57b23698124e5e0087ddfdc3a40f0eb26b6162089ed740888c325248cb49c69d7bee230a4df2817c094f2179f72ae5b284a844a2a1cb34239
|
7
|
+
data.tar.gz: 161e04475ee56b531af8ad5b1b8dc65ebc601ad3c2dbd02cc833b87e78d3efe7d595d9bf3b3165da771eec12fc25283be935247ed1e1c6d0eeaded4f9c725d0e
|
data/CHANGELOG.md
CHANGED
@@ -9,6 +9,13 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
|
|
9
9
|
### Compatible changes
|
10
10
|
|
11
11
|
|
12
|
+
## 0.15.1 - 2018-11-05
|
13
|
+
|
14
|
+
### Compatible changes
|
15
|
+
|
16
|
+
- Add `#humanized_values` for the `mutliple: true` case.
|
17
|
+
|
18
|
+
|
12
19
|
## 0.15.0 - 2018-10-26
|
13
20
|
|
14
21
|
### Breaking changes
|
data/README.md
CHANGED
@@ -185,8 +185,8 @@ In this case, every *subset* of the given values is valid, for example `['pop',
|
|
185
185
|
For humanization, you can still use
|
186
186
|
|
187
187
|
```
|
188
|
-
song.
|
189
|
-
song.
|
188
|
+
song.humanized_genre('pop') # => "Pop music"
|
189
|
+
song.humanized_assignable_genres.last.humanized # => "Electronic music"
|
190
190
|
```
|
191
191
|
|
192
192
|
|
data/gemfiles/Gemfile.2.3.lock
CHANGED
data/gemfiles/Gemfile.3.2.lock
CHANGED
data/gemfiles/Gemfile.4.2.lock
CHANGED
data/gemfiles/Gemfile.5.0.lock
CHANGED
data/gemfiles/Gemfile.5.1.lock
CHANGED
@@ -37,7 +37,7 @@ module AssignableValues
|
|
37
37
|
def define_humanized_value_class_method
|
38
38
|
restriction = self
|
39
39
|
enhance_model_singleton do
|
40
|
-
define_method :"humanized_#{restriction.property}" do |given_value|
|
40
|
+
define_method :"humanized_#{restriction.property.to_s.singularize}" do |given_value|
|
41
41
|
restriction.humanized_value(given_value)
|
42
42
|
end
|
43
43
|
end
|
@@ -55,6 +55,19 @@ module AssignableValues
|
|
55
55
|
value = given_value || send(restriction.property)
|
56
56
|
restriction.humanized_value(value)
|
57
57
|
end
|
58
|
+
|
59
|
+
if multiple
|
60
|
+
define_method :"humanized_#{restriction.property}" do
|
61
|
+
values = send(restriction.property)
|
62
|
+
if values.respond_to?(:map)
|
63
|
+
values.map do |value|
|
64
|
+
restriction.humanized_value(value)
|
65
|
+
end
|
66
|
+
else
|
67
|
+
values
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
58
71
|
end
|
59
72
|
end
|
60
73
|
|
@@ -21,7 +21,7 @@ describe AssignableValues::ActiveRecord do
|
|
21
21
|
%w[pop rock]
|
22
22
|
end
|
23
23
|
|
24
|
-
assignable_values_for :multi_genres, :allow_blank => true do
|
24
|
+
assignable_values_for :multi_genres, :multiple => true, :allow_blank => true do
|
25
25
|
%w[pop rock]
|
26
26
|
end
|
27
27
|
end
|
@@ -98,6 +98,10 @@ describe AssignableValues::ActiveRecord do
|
|
98
98
|
assignable_values_for :genre do
|
99
99
|
%w[pop rock]
|
100
100
|
end
|
101
|
+
|
102
|
+
assignable_values_for :multi_genres, :multiple => true, :allow_blank => true do
|
103
|
+
%w[pop rock]
|
104
|
+
end
|
101
105
|
end
|
102
106
|
end
|
103
107
|
|
@@ -159,6 +163,31 @@ describe AssignableValues::ActiveRecord do
|
|
159
163
|
@klass.humanized_genre('rock').should == 'Rock music'
|
160
164
|
end
|
161
165
|
|
166
|
+
context 'for multiple: true' do
|
167
|
+
it 'should raise when trying to humanize a value without an argument' do
|
168
|
+
song = @klass.new
|
169
|
+
proc { song.humanized_multi_genre }.should raise_error(ArgumentError)
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should generate an instance method to retrieve the humanization of any given value' do
|
173
|
+
song = @klass.new(:genre => 'pop')
|
174
|
+
song.humanized_multi_genre('rock').should == 'Rock music'
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'should generate a class method to retrieve the humanization of any given value' do
|
178
|
+
@klass.humanized_multi_genre('rock').should == 'Rock music'
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'should generate an instance method to retrieve the humanizations of all current values' do
|
182
|
+
song = @klass.new
|
183
|
+
song.multi_genres = nil
|
184
|
+
song.humanized_multi_genres.should == nil
|
185
|
+
song.multi_genres = []
|
186
|
+
song.humanized_multi_genres.should == []
|
187
|
+
song.multi_genres = ['pop', 'rock']
|
188
|
+
song.humanized_multi_genres.should == ['Pop music', 'Rock music']
|
189
|
+
end
|
190
|
+
end
|
162
191
|
end
|
163
192
|
|
164
193
|
context 'if the :allow_blank option is set to true' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assignable_values
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.15.
|
4
|
+
version: 0.15.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henning Koch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
version: '0'
|
91
91
|
requirements: []
|
92
92
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.7.
|
93
|
+
rubygems_version: 2.7.6
|
94
94
|
signing_key:
|
95
95
|
specification_version: 4
|
96
96
|
summary: Restrict the values assignable to ActiveRecord attributes or associations
|