json_api_model 0.3.1 → 0.3.2

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: c467af332f106f461c84f359e67298dd69cb986a
4
- data.tar.gz: 23a89ca934c867f85e4fcfd82f66f50f9bda0396
3
+ metadata.gz: b6f8100a1075e901d8733ccea171cb0fa211de66
4
+ data.tar.gz: d1fa53d8997a473bd2efc1b83b8e9cf65fdef14b
5
5
  SHA512:
6
- metadata.gz: e48f666314dfd88b60b2f74c09c2ca57fbe0ee6c2274a1f06c1330db4306f873ad3c280f30bd5d74027420a5b6bf66742db53dc570ccd2c0e8d790a1f19cfe43
7
- data.tar.gz: cc761bb1573596a40d5b5cc4dc0a46db210677cb49a555737dd5b27a94287d49edf66a8e7d99247e1b35cf2188e81d4db08ccd837ced73a4a59e32f8a89e709e
6
+ metadata.gz: 8eef7df9cc3053feaa2600a7b38a87fdb17d6f1a8a3df89e8ed8390470cff0f8479422e328e91a29948fc7ffc4befc3a36371a4518a20b2afd75675f97df5316
7
+ data.tar.gz: 8228712a1522f1d91bf3771b0afa41895dae137095541b45cbbe31a9f8c1fdac4773ccaa187dce137176ff1e9f2ffbfacddfa668a39457165c09a529345521bb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- json_api_model (0.3.1)
4
+ json_api_model (0.3.2)
5
5
  activesupport
6
6
  json_api_client
7
7
 
data/README.md CHANGED
@@ -65,9 +65,10 @@ Associations have some of the standard ActiveRecord options. Namely:
65
65
  end
66
66
  ```
67
67
 
68
+ __NOTE__: Due to perf implications the following are __only__ available for local classes (not things that come through the `relatinships` block in the payload). This will __*never ever*__ be available for remote models.
69
+
68
70
  * `through`: many to may association helper.
69
71
 
70
- __NOTE__: Due to perf implications this is __only__ available for local classes (not things that come through the `relatinships` block in the payload). This will __*never ever*__ be available for remote models.
71
72
 
72
73
  ```ruby
73
74
  class Person < JsonApiModel::Model
@@ -86,6 +87,19 @@ __NOTE__: Due to perf implications this is __only__ available for local classes
86
87
  end
87
88
  ```
88
89
 
90
+ * `as`: specifies what the associated object calls the caller
91
+ ```ruby
92
+ class Person < JsonApiModel::Model
93
+ wraps MyApi::Client::Person
94
+ has_many :images, as: :target
95
+ end
96
+
97
+ class Image < ActiveRecord::Base
98
+ belongs_to :target
99
+ end
100
+ ```
101
+ __NOTE__: only works for `has_one` and `has_many`
102
+
89
103
  ### Example
90
104
 
91
105
  If you have an app that talks to a `user` service. Here's how your `User` model might look:
@@ -11,13 +11,15 @@ module JsonApiModel
11
11
  { id: instance.relationship_ids( name ) }
12
12
  elsif through?
13
13
  { id: target_ids( instance ) }
14
+ elsif as?
15
+ { "#{as}_id" => instance.id }
14
16
  else
15
17
  { key => instance.id }
16
18
  end
17
19
  end
18
20
 
19
21
  def additional_options
20
- [ :through ]
22
+ [ :as, :through ]
21
23
  end
22
24
 
23
25
  protected
@@ -30,6 +32,14 @@ module JsonApiModel
30
32
  opts.has_key? :through
31
33
  end
32
34
 
35
+ def as
36
+ opts[:as]
37
+ end
38
+
39
+ def as?
40
+ opts.has_key? :as
41
+ end
42
+
33
43
  def target_ids( instance )
34
44
  intermadiates = Array(instance.send( through ) )
35
45
 
@@ -1,3 +1,3 @@
1
1
  module JsonApiModel
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_api_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Orlov