scoped_serializer 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 196bfc01398816a75c990ce9a4f2e396c76330ca
4
- data.tar.gz: 538964d4220858ca63e3be103081440a4a097b00
3
+ metadata.gz: 5c32261f4040ce1b81c7e955dc1e0122163cde4d
4
+ data.tar.gz: b84e63cf91a309ea2b683af89cc260ea51028506
5
5
  SHA512:
6
- metadata.gz: e95f8288fe9eb945a9121aebf2813e4b50b4d83bd3c5a7f31c41af35aafe9a0592f025a85530ff51c0721c894173bb12099e72c3a4a7e7c1bc69db5d4dbc6987
7
- data.tar.gz: d199ad933211719006e154dd09fcb04a3e09ea472213c22f8808822e16e6a620da40fd0ffafa9d6bfaef8cdd2675a5cee38f97546b713a69dfe29c866da943fc
6
+ metadata.gz: db2ffb1aa94ce0bf5e6d57187079ecd7fc993e1429a718f4a13050e3449752bb45abda201d1ca1ac44e256c5ac3142f861a052cb33c2ad40db28a949d14ea8ab
7
+ data.tar.gz: 44234ef5494e7eacd4ed8a77a30e0718d6f89254143d50c8f3a1add90be4f00540f314686753a6bc2b3c110afe22dca0cacca027d256d5ec0d8a6c112492f20c
@@ -5,6 +5,27 @@ module ScopedSerializer
5
5
 
6
6
  attr_accessor :name, :attributes, :associations, :options
7
7
 
8
+ class << self
9
+
10
+ ##
11
+ # Initializes a scope from hash.
12
+ #
13
+ # @example
14
+ # Scope.from_hash({ :attributes => [:title, :created_at] })
15
+ #
16
+ def from_hash(data={})
17
+ scope = new self
18
+ scope.attributes *data[:attributes]
19
+
20
+ (data[:associations] || []).each do |association|
21
+ scope.association association
22
+ end
23
+
24
+ scope
25
+ end
26
+
27
+ end
28
+
8
29
  def initialize(name, default=nil, &block)
9
30
  @name = name
10
31
  @options = {}
@@ -72,6 +72,9 @@ module ScopedSerializer
72
72
  if scope.is_a?(Symbol)
73
73
  @scope_name = scope
74
74
  @scope = self.class.find_scope(scope)
75
+ elsif scope.is_a?(Hash)
76
+ @scope_name = :custom
77
+ @scope = Scope.from_hash(scope)
75
78
  else
76
79
  @scope_name = scope.name
77
80
  @scope = scope
@@ -1,3 +1,3 @@
1
1
  module ScopedSerializer
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scoped_serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arjen Oosterkamp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-26 00:00:00.000000000 Z
11
+ date: 2014-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails