pluck_all 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/lib/pluck_all.rb +8 -7
- data/lib/pluck_all/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f437fda05144e7f3e3954b6240f2b693755ab275
|
4
|
+
data.tar.gz: 764277729c198b2dee6c6e30c1d07c5f31341be0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3d83b3af48aff47a6435a7091571aeea203b53c877307f3af625bf55830be2af3dd9a007e144ba8aa73e05bae61aec34b390d03bba208eacba6cd454332273f
|
7
|
+
data.tar.gz: 44366aa3181d79553bf243c5aec694f12f324bfbe857cf6758203d1450f7074a85a17d323b3255bfbeaa2651c3160af3fec33b78627dd788a7fe85d49dbf4580
|
data/README.md
CHANGED
@@ -49,6 +49,20 @@ User.where('id < 3').pluck_all('id, account AS name')
|
|
49
49
|
# => [{"id"=>1, "name"=>"account1"}, {"id"=>2, "name"=>"account2"}]
|
50
50
|
```
|
51
51
|
|
52
|
+
### Support Pluck Carrierwave Uploader (if you use carrierwave)
|
53
|
+
```rb
|
54
|
+
User.where(xxx).pluck_all(:profile_pic).map{|s| s['profile_pic'] }
|
55
|
+
```
|
56
|
+
is the same as
|
57
|
+
```rb
|
58
|
+
User.where(xxx).map(&:profile_pic)
|
59
|
+
```
|
60
|
+
If the uploader use something like: `model.id`, `model.name`
|
61
|
+
You should send these columns manually:
|
62
|
+
```rb
|
63
|
+
User.where(xxx).cast_need_columns(%i(id, name)).pluck_all(:id, :name, :profile_pic).map{|s| s['profile_pic'] }
|
64
|
+
```
|
65
|
+
|
52
66
|
## Development
|
53
67
|
|
54
68
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/pluck_all.rb
CHANGED
@@ -48,7 +48,7 @@ class ActiveRecord::Relation
|
|
48
48
|
end
|
49
49
|
def cast_need_columns(column_names, _klass = nil)
|
50
50
|
@pluck_all_cast_need_columns = column_names.map(&:to_s)
|
51
|
-
@pluck_all_cast_klass = _klass
|
51
|
+
@pluck_all_cast_klass = _klass
|
52
52
|
return self
|
53
53
|
end
|
54
54
|
private
|
@@ -68,13 +68,14 @@ private
|
|
68
68
|
# Support casting CarrierWave url
|
69
69
|
#----------------------------------
|
70
70
|
def cast_carrier_wave_uploader_url(attributes)
|
71
|
-
if defined?(CarrierWave)
|
72
|
-
@pluck_all_cast_klass
|
73
|
-
|
71
|
+
if defined?(CarrierWave)
|
72
|
+
@pluck_all_cast_klass ||= klass
|
73
|
+
@pluck_all_uploaders ||= @pluck_all_cast_klass.uploaders.select{|key, uploader| attributes.key?(key.to_s) }
|
74
|
+
@pluck_all_uploaders.each do |key, uploader|
|
74
75
|
obj = @pluck_all_cast_klass.new
|
75
|
-
obj[key] =
|
76
|
-
@pluck_all_cast_need_columns.each{|s| obj[s] = attributes[s] }
|
77
|
-
attributes[
|
76
|
+
obj[key] = attributes[key_s = key.to_s]
|
77
|
+
@pluck_all_cast_need_columns.each{|s| obj[s] = attributes[s] } if @pluck_all_cast_need_columns
|
78
|
+
attributes[key_s] = obj.send(:_mounter, key).uploader #uploaders.first
|
78
79
|
end
|
79
80
|
end
|
80
81
|
return attributes
|
data/lib/pluck_all/version.rb
CHANGED