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 +4 -4
- data/README.md +15 -1
- data/app/serializers/upframework/base_serializer.rb +56 -0
- data/lib/upframework/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65b7cd4203031fe204ae2db4b2e9f15234f70b9f8319c0b0eb0479a93b8d775d
|
4
|
+
data.tar.gz: bab9c34c224ae19444350453b103a6658bba142351ef54a516d602b34f869ca5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/upframework/version.rb
CHANGED
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.
|
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-
|
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:
|
48
|
+
name: jsonapi-serializer
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
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: '
|
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
|