upframework 0.2.7 → 0.2.8

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
  SHA256:
3
- metadata.gz: 56bea5267caba929195f4ff4692e20b9d82fa351fdb1817b3b104097e8e4f820
4
- data.tar.gz: 9af1be007b1c7fa9555c58bb285f747f0a6130ba54185c2133a3d629a65fe3bd
3
+ metadata.gz: 65b7cd4203031fe204ae2db4b2e9f15234f70b9f8319c0b0eb0479a93b8d775d
4
+ data.tar.gz: bab9c34c224ae19444350453b103a6658bba142351ef54a516d602b34f869ca5
5
5
  SHA512:
6
- metadata.gz: 39c6363e11e759b624d708c43746b7c6bc932303cdd707a68dfab54df484794fb805db17a7beb2a09a48adc533d24be93c3afc50f850af2aadd19250c4a03cdb
7
- data.tar.gz: f9fba79249385101c923241637c772a0e44b057223c71e30ae9af2ab9e9014601f7dd32c73f9fa5c8edf01a1c2dfbcb028fe3e1f68fc4028c4acb0140565f135
6
+ metadata.gz: 98e0d8b2a6405ccd13098554c6c219b9b1f3bc551c9d321f4378a71bb39cbd468a34260818b2f0a14abeba83060a9692fdf86163fbf8d92d2121b836ea67efcd
7
+ data.tar.gz: 93d0add617417cfd7fe6052d6557525fc22626069032a37677e9b9d5ba43257828694ad35edca4eec0f676e75f8ec510ffc876c2aa9cd208442dbf48dc12492e
data/README.md CHANGED
@@ -30,6 +30,20 @@ class ProjectsController < Upframework::ResourcesController
30
30
  end
31
31
  ```
32
32
 
33
+
34
+ #### Serializers
35
+ ```ruby
36
+ # app/serializers
37
+ # classes extending Upframework::BaseSerializer has pagination and meta data enabled
38
+ class ProjectSerializer < Upframework::BaseSerializer
39
+ belongs_to :user
40
+
41
+ has_many :tasks
42
+
43
+ default_includes [:user]
44
+ end
45
+ ```
46
+
33
47
  #### Searches
34
48
  ```ruby
35
49
  #app/searches
@@ -82,7 +96,7 @@ mount Upframework::Engine => /path
82
96
  routes being available
83
97
  ```
84
98
  GET /search
85
- POST /services/:service_name
99
+ POST /{resource}/services/:service_name
86
100
  ```
87
101
 
88
102
  ## Installation
@@ -0,0 +1,56 @@
1
+ module Upframework
2
+ class BaseSerializer
3
+ include JSONAPI::Serializer
4
+
5
+ attr_reader :resource, :current_controller
6
+
7
+ delegate :view_context, to: :current_controller
8
+
9
+ set_key_transform :camel_lower
10
+ attributes :created_at, :updated_at
11
+
12
+ def initialize(resource, current_controller: nil, **args)
13
+ @resource = resource
14
+ @current_controller = current_controller
15
+
16
+ if args[:format] == :minimal
17
+ args[:fields] = set_format
18
+ end
19
+
20
+ if @current_controller && resource.respond_to?(:total_pages)
21
+ args.merge!(pagination)
22
+ end
23
+
24
+ super(resource, **args)
25
+ end
26
+
27
+ def set_format
28
+ resource_klass = resource.class.name
29
+ resource_klass = resource.klass.name if resource_klass == 'ActiveRecord::Relation'
30
+ resource_klass = resource.first.class.name if resource.kind_of?(Array)
31
+
32
+ { resource_klass.camelize(:lower) => [:id] }
33
+ end
34
+
35
+ def pagination
36
+ {
37
+ meta: {
38
+ per_page: resource.size,
39
+ total_pages: resource.total_pages,
40
+ },
41
+ links: {
42
+ prev: view_context.path_to_prev_page(resource),
43
+ next: view_context.path_to_next_page(resource),
44
+ },
45
+ }.deep_transform_keys { |key| key.to_s.camelize(:lower).to_sym }
46
+ end
47
+
48
+ def self.default_includes(relations = [])
49
+ @relations ||= relations
50
+ end
51
+
52
+ class << self
53
+ delegate :url_helpers, to: :'Rails.application.routes'
54
+ end
55
+ end
56
+ end
@@ -1,3 +1,3 @@
1
1
  module Upframework
2
- VERSION = '0.2.7'
2
+ VERSION = '0.2.8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upframework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - jude_cali
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-30 00:00:00.000000000 Z
11
+ date: 2020-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -45,19 +45,19 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: 3.1.0
47
47
  - !ruby/object:Gem::Dependency
48
- name: fast_jsonapi
48
+ name: jsonapi-serializer
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '1.5'
53
+ version: '2.0'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '1.5'
60
+ version: '2.0'
61
61
  description: Rails framework extensions
62
62
  email:
63
63
  - jcalimbas@fullscale.io
@@ -82,6 +82,7 @@ files:
82
82
  - app/mailers/upframework/application_mailer.rb
83
83
  - app/models/upframework/application_record.rb
84
84
  - app/searches/upframework/base_search.rb
85
+ - app/serializers/upframework/base_serializer.rb
85
86
  - app/services/concerns/upframework/service_endpoint.rb
86
87
  - app/services/upframework/base_service.rb
87
88
  - app/views/layouts/upframework/application.html.erb