upframework 0.2.4 → 0.2.91

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
  SHA256:
3
- metadata.gz: 3b9df2b3fab51ad8cd9df13ce48c23de3f7de3345a732950f1133de10468443b
4
- data.tar.gz: e964a3112339f87964455696b87788e9fca05f75be7fbda0edc4a22a772b667d
3
+ metadata.gz: 801f75afeb73f9ebbaa429e0699f8e808f258a58debe206ed5cda954fb97fdb8
4
+ data.tar.gz: b40be74dab664d2c3fcd5997bafd797a578c71a767bb15db07f93e01f8bf5cba
5
5
  SHA512:
6
- metadata.gz: 3dccc34d6735c68b9bc5ab6e0feb4084bb33ec67df5627a20e8bb6b5e4668795dbc063e399bddf03895168a51b28235b0e7b879f1ae882b4989a7f9a4a670c00
7
- data.tar.gz: 0be54b8cad4e95f88314aa60f8ecf9e02f0482fa97f1e202edb4b96a9321beeb16c8b107f0d3245958a85f1965bd8a9944302e98733c505baecc2e9353068f95
6
+ metadata.gz: 7d79cfd3ca644a503593cdaeaad0692074261cddc045960a33190bd33c199c7b993f60386fc88b892754cc3711b6a52f47a9ec6c666ca90cf50e7cf53f3338bf
7
+ data.tar.gz: 05a7471d324141b0db6c68ef55498a8ed016eb90b1634e89dc40a0f0415bb96016eef220d89709c7d3c72416bfcbc7acbee5ca1acaabfd4ffe07db1a563b97c1
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
@@ -16,7 +16,9 @@ module Upframework::ErrorHandler
16
16
  ExceptionNotifier.notify_exception(error, env: request.env)
17
17
 
18
18
  error_info = {
19
+ success: false,
19
20
  error: 'Internal Server Error',
21
+ status_code: 500,
20
22
  exception: "#{error.class.name} : #{error.message}"
21
23
  }
22
24
 
@@ -22,10 +22,7 @@ module Upframework
22
22
  # format => format can be :full(returns all default) or :minimal(returns only ids an types)
23
23
  # compound_opts => options, e.g: meta or links
24
24
  # opts => extra options from render
25
- def broadcast_serialized(channel, resource:, event:, includes: [], format: :full, compound_opts: {})
26
- includes << :events
27
- resource.add_event(event, creator: current_member)
28
-
25
+ def broadcast_serialized(channel, resource:, includes: [], format: :full, compound_opts: {})
29
26
  channel_klass = "::#{channel.class.name}Channel".constantize
30
27
  channel_klass.broadcast_to(channel, serialize_resource(resource, includes, format, compound_opts))
31
28
  end
@@ -15,7 +15,7 @@ module Upframework
15
15
 
16
16
  rescue_from CanCan::AccessDenied do |exception|
17
17
  respond_to do |format|
18
- format.json { render json: { success: false, error: exception.message }, status: :forbidden }
18
+ format.json { render json: { success: false, error: exception.message, status_code: 403 }, status: :forbidden }
19
19
  format.html { redirect_to main_app.root_url, alert: exception.message }
20
20
  end
21
21
  end
@@ -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.4'
2
+ VERSION = '0.2.91'
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.4
4
+ version: 0.2.91
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-08-03 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