simple_ams 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21432f80bcadd512b56d7d24023014944e746d2b
4
- data.tar.gz: 0d8dc9ac8b88a4b25483168fc2c88023831ec863
3
+ metadata.gz: 7466c8f4a93d634a5694e11369c829b5cd125e2f
4
+ data.tar.gz: 40ca860c3304907242ed9b357b1d0f2663faf977
5
5
  SHA512:
6
- metadata.gz: b8efe4cea91158fb2cc4e2ed7f45b464cd78e61ea45a97dbf1e42f066c493dc07d468fbe3d2317ea40838bd71e8766c2556be2fd222ec3fdb0de8a090bac155b
7
- data.tar.gz: c390be3c1c6b9a91b95916f761e7c4ccdd98ee9653ac9df969c4e42e915f78dcfa81311ddb0eb0f83e427054f5be7e05d53750c018255b8d86d72d763d5cfc9c
6
+ metadata.gz: 2ec2ba04017b4db14d5178dcc6f9ac11b1a50035a5971bd8a8b6b3c1dd1aebdae307d953078a7fd498fb32f2f689f5658adc5ce909ed41bc7c60519be9762efc
7
+ data.tar.gz: ddd1b7ebfc152dd071a19f5cb23f1ce154aee16c33536d8cb4ad997376a855743d208eceef23b18d5ce6a64d79d53e9a03f6e2d1e1bc53f62c3499aeea951796
data/README.md CHANGED
@@ -58,15 +58,16 @@ class UserSerializer
58
58
  #links can also take other options, as specified by RFC 8288
59
59
  link :root, '/api/v1/', rel: :user
60
60
  #link values can be dynamic as well through lambdas
61
- link :posts, ->(obj) { "/api/v1/users/#{obj.id}/posts/" }, rel: :user
61
+ #lambdas take arguments the object to be serialized and the instantiated serializer
62
+ link :posts, ->(obj, s) { "/api/v1/users/#{obj.id}/posts/" }, rel: :user
62
63
  #if you also need dynamic options, you can return an array from the lambda
63
- link :followers, ->(obj) { ["/api/v1/users/#{obj.id}/followers/", rel: obj.type] }
64
+ link :followers, ->(obj, s) { ["/api/v1/users/#{obj.id}/followers/", rel: obj.type] }
64
65
 
65
66
  #same with metas: can be static, dynamic and accept arbitrary options
66
- meta :environment, ->(obj) { Rails.env.to_s }
67
+ meta :environment, ->(obj, s) { Rails.env.to_s }
67
68
 
68
69
  #same with form: can be static, dynamic and accept arbitrary options
69
- form :create, ->(obj) { User::CreateForm.for(obj) }
70
+ form :create, ->(obj, s) { User::CreateForm.for(obj) }
70
71
 
71
72
  #or if you need something quite generic (and probably adapter-related)
72
73
  #again it follows the same patterns as link
@@ -80,7 +81,7 @@ class UserSerializer
80
81
  #here we use only links and meta
81
82
  link :root, '/api/v1/', rel: :user
82
83
  type :users
83
- meta :count, ->(collection) { collection.count }
84
+ meta :count, ->(collection, s) { collection.count }
84
85
  end
85
86
 
86
87
  #note that most probably the only thing that you will need here is the `type`,
@@ -143,7 +144,7 @@ In any case, we have the following options:
143
144
  #makes sense to use it when initializing the Renderer
144
145
  serializer: UserSerializer,
145
146
  #can also be a lambda, in case of polymorphic records, ideal for ArrayRenderer
146
- serializer: ->(obj){ obj.employee? ? EmployeeSerializer : UserSerializer }
147
+ serializer: ->(obj, s){ obj.employee? ? EmployeeSerializer : UserSerializer }
147
148
  #specifying the underlying adapter. This cannot be a lambda in case of ArrayRenderer,
148
149
  #but can take some useful options that are passed down straight to the adapter class.
149
150
  adapter: SimpleAMS::Adapters::AMS, root: true
@@ -156,18 +157,18 @@ In any case, we have the following options:
156
157
  posts: "/api/v1/posts/", rel: :posts,
157
158
  #it can also be a lambda that takes the resource to be rendered as a param
158
159
  #when the lambda is called, it should return the array structure above
159
- self: ->(obj) { ["/api/v1/users/#{obj.id}", rel: :user] }
160
+ self: ->(obj, s) { ["/api/v1/users/#{obj.id}", rel: :user] }
160
161
  },
161
162
  #the meta data, same as the links data (available in adapters even for single records)
162
163
  metas: {
163
- type: ->(obj){ obj.employee? ? :employee : :user}
164
+ type: ->(obj, s){ obj.employee? ? :employee : :user}
164
165
  #meta can take arbitrary options as well
165
166
  authorization: :oauth, type: :bearer_token
166
167
  },
167
168
  #the form data, same as the links/metas data (available in adapters even for single records)
168
169
  forms: {
169
- update: ->(obj){ User::UpdateForm.for(obj)}
170
- follow: ->(obj){ User::FollowForm.for(obj)}
170
+ update: ->(obj, s){ User::UpdateForm.for(obj)}
171
+ follow: ->(obj, s){ User::FollowForm.for(obj)}
171
172
  },
172
173
  #collection parameters, used only in ArrayRenderer
173
174
  collection: {
@@ -175,10 +176,10 @@ In any case, we have the following options:
175
176
  root: '/api/v1'
176
177
  },
177
178
  metas: {
178
- pages: ->(obj) { [obj.pages, collection: true]},
179
- current_page: ->(obj) { [obj.current_page, collection: true] },
180
- previous_page: ->(obj) { [obj.previous_page, collection: true] },
181
- next_page: ->(obj) { [obj.next_page, collection: true] },
179
+ pages: ->(obj, s) { [obj.pages, collection: true]},
180
+ current_page: ->(obj, s) { [obj.current_page, collection: true] },
181
+ previous_page: ->(obj, s) { [obj.previous_page, collection: true] },
182
+ next_page: ->(obj, s) { [obj.next_page, collection: true] },
182
183
  max_per_page: 50,
183
184
  },
184
185
  #creating a resource goes in the collection route (users/), hence inside collection options ;)
@@ -9,6 +9,8 @@ class SimpleAMS::Adapters::AMS
9
9
  end
10
10
 
11
11
  def as_json
12
+ return nil if document.resource.nil?
13
+
12
14
  hash = {}
13
15
 
14
16
  hash.merge!(fields)
@@ -1,3 +1,3 @@
1
1
  module SimpleAMS
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_ams
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Filippos Vasilakis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-01 00:00:00.000000000 Z
11
+ date: 2018-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler