json_api_model 0.1.2 → 0.2.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: c0c2e854a3a779030b0ab788040d6481ec4f72c8
4
- data.tar.gz: 0bac3b49d6310dca35407b67411e615d6d422643
3
+ metadata.gz: 89df9b9d8d8f4ae17c7bcd671f8f272b0339c5bc
4
+ data.tar.gz: 7db7eac6d7c3d4398fc3b912f23eed7f90c631f2
5
5
  SHA512:
6
- metadata.gz: 4733844d6db1d48f8353d0e384bdfaa8e3695e51260668bdf546ca9e7c625ea21d218c295f5f663df34628301392d3d20517c7d8619559a7d5d3e67189e843db
7
- data.tar.gz: 92d708f1e39de4cdb028785cc489edc3029b8c99e5d8631129500e225d62dfeca65d60a506fa30bd0f6f9f104d602e658f0055d01ef29cf32b68f5a76b823910
6
+ metadata.gz: 0eb9b10ac0e5a56e2bb2307e7e2b9cde7fce35d2a409d34df9490e616a01902d801274032539db5062bfc62634a865ef7045276836972566671e43e657a0cab9
7
+ data.tar.gz: 03f7d39b4504ff47099aaec9fec4b9934f58cd31314a6ad1cd0712784c5b5f4e994332b477f00ebc06025147bfa07b4deb47d81b6b2977af559244b845691a75
data/.travis.yml CHANGED
@@ -1,5 +1,14 @@
1
1
  sudo: false
2
+ env:
3
+ global:
4
+ - CC_TEST_REPORTER_ID=c174e3bfd117918fe3df02942dea49339cc60d47bcca258b764431d7474f9fc1
2
5
  language: ruby
3
6
  rvm:
4
7
  - 2.4.3
8
+ before_script:
9
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
10
+ - chmod +x ./cc-test-reporter
11
+ - ./cc-test-reporter before-build
5
12
  before_install: gem install bundler -v 1.16.1
13
+ after_script:
14
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile CHANGED
@@ -1,6 +1,3 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in json_api_model.gemspec
6
3
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- json_api_model (0.1.1)
4
+ json_api_model (0.1.2)
5
5
  json_api_client
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # JsonApiModel
2
2
 
3
+ [![Build Status](https://travis-ci.org/gaorlov/json_api_model.svg?branch=master)](https://travis-ci.org/gaorlov/json_api_model)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/31b0f67e5ece127dbb67/maintainability)](https://codeclimate.com/github/gaorlov/json_api_model/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/31b0f67e5ece127dbb67/test_coverage)](https://codeclimate.com/github/gaorlov/json_api_model/test_coverage)
6
+
3
7
  Much like `ActiveRecord` is an ORM on top of your database, [`JSON API Client`](https://github.com/JsonApiClient/json_api_client) is an ORM specific to a service. This gem is the `app/models/` on top of `json_api_client`.
4
8
 
5
9
  Yes, you can put business in the client, but if you need to distrubute the gem, you will want that to live somewhere else. This gem provides a thin wrapper layer to let you do that.
@@ -20,9 +24,6 @@ Or install it yourself as:
20
24
 
21
25
  $ gem install json_api_model
22
26
 
23
- ## Disclaimer
24
-
25
- This is a work in progress. Right now only fetching data works. This will soon change.
26
27
 
27
28
  ## Usage
28
29
 
@@ -46,7 +47,7 @@ module UserService
46
47
  end
47
48
  ```
48
49
 
49
- And the interaction with it is not that different from how you would work with the client:
50
+ And the interaction with it is identical as how you would work with the client:
50
51
 
51
52
  ```ruby
52
53
  # fetching looks identical to as json_api_client (because it thinly wraps it)
@@ -60,6 +61,16 @@ user.lucky_number
60
61
  # but also transparently access the client properties
61
62
  user.id
62
63
  # => 8
64
+
65
+ # creating new users
66
+ new_user = UserService::User.new name: "greg"
67
+ # => #<UserService::User:0x000055e1fc1c8c00 @client=#<UserService::Client::User:@attributes={"type"=>"users", "name"=>"greg"}>>
68
+ new_user.save
69
+ # => true
70
+
71
+ # and now that the record is saved, you can search for it and get back a JsonApiModel back to keep working with
72
+ UserService::User.where( name: "greg" ).first
73
+ # => #<UserService::User:0x000055e1fc1c8c00 @client=#<UserService::Client::User:@attributes={"type"=>"users", "name"=>"greg", "id"=>"9"}>>
63
74
  ```
64
75
 
65
76
  ### Rendering
@@ -20,6 +20,20 @@ module JsonApiModel
20
20
  client_class.connection true, &block
21
21
  end
22
22
 
23
+ def method_missing( m, *args, &block )
24
+ result = client_class.send m, *args, &block
25
+ case result
26
+ when JsonApiClient::ResultSet
27
+ JsonApiModel::ResultSet.new( result, self )
28
+ when client_class
29
+ new_from_client result
30
+ else
31
+ result
32
+ end
33
+ rescue NoMethodError
34
+ raise NoMethodError, "No method `#{m}' found in #{self} or #{client_class}"
35
+ end
36
+
23
37
  private
24
38
 
25
39
  def _new_scope
@@ -35,6 +49,8 @@ module JsonApiModel
35
49
 
36
50
  def method_missing( m, *args, &block )
37
51
  client.send m, *args, &block
52
+ rescue NoMethodError
53
+ raise NoMethodError, "No method `#{m}' found in #{self} or #{client}"
38
54
  end
39
55
 
40
56
  def as_json
@@ -1,8 +1,8 @@
1
1
  module JsonApiModel
2
2
  class Scope
3
3
  def initialize( model_class )
4
- @model_class = model_class
5
- @client_scope = JsonApiClient::Query::Builder.new( model_class.client_class )
4
+ @model_class = model_class
5
+ @client_scope = JsonApiClient::Query::Builder.new( model_class.client_class )
6
6
  end
7
7
 
8
8
  def to_a
@@ -33,10 +33,6 @@ module JsonApiModel
33
33
  end
34
34
  end
35
35
 
36
- def build
37
- @model_class.new_from_client @client_scope.build
38
- end
39
-
40
36
  def params
41
37
  @client_scope.params
42
38
  end
@@ -1,3 +1,3 @@
1
1
  module JsonApiModel
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_api_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Orlov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-12 00:00:00.000000000 Z
11
+ date: 2018-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_api_client