jsonapi_utils 0.1.0 → 0.1.1

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: 84ec82ef1641e1fd29946ff8a585a66a97cd9ba0
4
- data.tar.gz: 1be29030137e603d3a324271751babfa6345f91f
3
+ metadata.gz: 822234bc0b0f6d66c3a41eb75b93232e99eecbf4
4
+ data.tar.gz: 6730613246e3cfd71c35e8a52bb5fa0978646c95
5
5
  SHA512:
6
- metadata.gz: 94237460f45e983ec4f915d05903cefbc36ab88fbd63f1ab93eacc5f45ac27cde11221e453ccb7ea1303fc5982315afeb57c5eeb5349960f7e816e23c436d1db
7
- data.tar.gz: 15cffa208ff216997d4be1d5f187ab627a87678d0fd57c738d82caaeb533c0bd75464370e2a7984dd676703f0d9c043930ea937cb1296383a1bdfc0dc43d0f61
6
+ metadata.gz: b958e77ab3b5ed4b8e1a83ff1c971a2958523577769cfd32eecb01cfd11a710f845e23b9fe205378c08ce6255cc945c1051a68e0345a79d716c78c1f83252edf
7
+ data.tar.gz: 77176da0b129f8454a661ccdb36269fc841fc596eeebf86201c1cfd2cf480a9235fac7f00e9e0987684c3c5f23c9518f316d761625cffc8b02167e0d9370a13d
data/.gitignore CHANGED
@@ -7,3 +7,10 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.sw*
13
+ *.o
14
+ *.a
15
+ mkmf.log
16
+
data/README.md CHANGED
@@ -2,7 +2,15 @@
2
2
 
3
3
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jsonapi_utils`. To experiment with that code, run `bin/console` for an interactive prompt.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ Required doc:
6
+
7
+ * Describe something about the awesome `jsonapi-resources` gem
8
+ * Describe how it's easy to serialize JSON API-based responses using the `jsonapi_utils` gem
9
+ * JsonapiUtils#jsonapi_render (show options like `json`, `resource`, `model`, `scope` and `count`)
10
+ * JsonapiUtils#jsonapi_serialize
11
+ * Example of a model
12
+ * Example of a resource
13
+ * Example of a base controller and another whatever controller
6
14
 
7
15
  ## Installation
8
16
 
@@ -1,3 +1,3 @@
1
1
  module JsonapiUtils
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/jsonapi_utils.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  require "jsonapi_utils/version"
2
2
 
3
+ # TODO:
4
+ # 1. Create a test suite;
5
+ # 2. Refactor and separate into submodules;
6
+ # 3. Include 'version' field in the meta node.
3
7
  module JsonapiUtils
4
8
  extend ActiveSupport::Concern
5
9
 
@@ -20,14 +24,13 @@ module JsonapiUtils
20
24
 
21
25
  if records.respond_to?(:to_ary)
22
26
  records = fix_when_hash(records, options) if records.all? { |e| e.is_a?(Hash) }
23
- @resources = build_collection(records)
27
+ @resources = build_collection(records, options)
24
28
  results.add_result(JSONAPI::ResourcesOperationResult.new(:ok, @resources, result_options(options)))
25
29
  else
26
- @resource = turn_into_resource(records)
30
+ @resource = turn_into_resource(records, options)
27
31
  results.add_result(JSONAPI::ResourceOperationResult.new(:ok, @resource))
28
32
  end
29
-
30
- create_response_document(results).contents
33
+ create_response_document(results, options).contents
31
34
  end
32
35
 
33
36
  def jsonapi_error(exception)
@@ -70,15 +73,19 @@ module JsonapiUtils
70
73
  end
71
74
 
72
75
 
73
- def build_collection(records)
76
+ def build_collection(records, options = {})
74
77
  return [] unless records.present?
75
78
  paginator(@request.params).apply(records, nil).map do |record|
76
- turn_into_resource(record)
79
+ turn_into_resource(record, options)
77
80
  end
78
81
  end
79
82
 
80
- def turn_into_resource(record)
81
- @request.resource_klass.new(record)
83
+ def turn_into_resource(record, options = {})
84
+ if options[:resource]
85
+ options[:resource].new(record)
86
+ else
87
+ @request.resource_klass.new(record)
88
+ end
82
89
  end
83
90
 
84
91
  def paginator(params)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Guedes
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-08 00:00:00.000000000 Z
11
+ date: 2015-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,9 +73,7 @@ files:
73
73
  - bin/console
74
74
  - bin/setup
75
75
  - jsonapi_utils.gemspec
76
- - lib/.jsonapi_utils.rb.swp
77
76
  - lib/jsonapi_utils.rb
78
- - lib/jsonapi_utils/.version.rb.swp
79
77
  - lib/jsonapi_utils/version.rb
80
78
  homepage: https://github.com/b2beauty/jsonapi_utils
81
79
  licenses:
Binary file
Binary file