datasource 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/datasource/adapters/sequel.rb +1 -1
- data/lib/datasource/attributes/loader.rb +4 -0
- data/lib/datasource/base.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: 107812940a2c8fc80ebec710b0ebd63c5f710fd4
|
4
|
+
data.tar.gz: b0d4b77a9cace8c1f559d39738065cfe69930c55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 960aa77805c5fe4e0a2c1ac658956bf0c2b4d8e81769c96850a012b5e95facac053ba6407f1b8d88ec65749b7ecc813fb6229502302ea4d070873b4483d8113f
|
7
|
+
data.tar.gz: 22dad36f267317cb360ffc30d035b8efd3074faa3ae801e26bbef76c3b9c9d358f417f8a0dee31cf37ea9a49c92e33afe472a753b2d86276e13319cf72b057e8
|
data/README.md
CHANGED
@@ -151,13 +151,13 @@ A loader will only be executed if a computed attribute depends on it. If an attr
|
|
151
151
|
on multiple loaders, pass an array of loaders like so `computed :attr, loaders: [:loader1, :loader2]`.
|
152
152
|
|
153
153
|
Be careful that if your hash does not contain a value for the object ID, the loaded value
|
154
|
-
will be nil.
|
154
|
+
will be nil. However you can use the `default` option for such cases (see below example).
|
155
155
|
|
156
156
|
```ruby
|
157
157
|
class User < ActiveRecord::Base
|
158
158
|
datasource_module do
|
159
159
|
computed :post_count, loaders: :post_counts
|
160
|
-
loader :post_counts, array_to_hash: true do |user_ids|
|
160
|
+
loader :post_counts, array_to_hash: true, default: 0 do |user_ids|
|
161
161
|
results = Post
|
162
162
|
.where(user_id: user_ids)
|
163
163
|
.group(:user_id)
|
@@ -171,7 +171,7 @@ class UserSerializer < ActiveModel::Serializer
|
|
171
171
|
|
172
172
|
def post_count
|
173
173
|
# Will automatically give you the value for this user's ID
|
174
|
-
object.loaded_values[:post_counts]
|
174
|
+
object.loaded_values[:post_counts]
|
175
175
|
end
|
176
176
|
end
|
177
177
|
```
|
@@ -48,7 +48,7 @@ module Datasource
|
|
48
48
|
scope = if respond_to?(:use_datasource_serializer)
|
49
49
|
self
|
50
50
|
else
|
51
|
-
self.extend(ScopeExtensions).use_datasource(default_datasource)
|
51
|
+
self.extend(ScopeExtensions).use_datasource(Adapters::Sequel.scope_to_class(self).default_datasource)
|
52
52
|
end
|
53
53
|
scope.use_datasource_serializer(serializer || Datasource::Base.consumer_adapter.get_serializer_for(Adapters::Sequel.scope_to_class(scope)))
|
54
54
|
end
|
data/lib/datasource/base.rb
CHANGED