upframework 0.2.1 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +84 -3
- data/app/searches/upframework/base_search.rb +10 -3
- data/lib/upframework/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56bea5267caba929195f4ff4692e20b9d82fa351fdb1817b3b104097e8e4f820
|
4
|
+
data.tar.gz: 9af1be007b1c7fa9555c58bb285f747f0a6130ba54185c2133a3d629a65fe3bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39c6363e11e759b624d708c43746b7c6bc932303cdd707a68dfab54df484794fb805db17a7beb2a09a48adc533d24be93c3afc50f850af2aadd19250c4a03cdb
|
7
|
+
data.tar.gz: f9fba79249385101c923241637c772a0e44b057223c71e30ae9af2ab9e9014601f7dd32c73f9fa5c8edf01a1c2dfbcb028fe3e1f68fc4028c4acb0140565f135
|
data/README.md
CHANGED
@@ -1,8 +1,89 @@
|
|
1
1
|
# Upframework
|
2
|
-
|
2
|
+
Add features on top of Rails, Especially for APIs. This was created to make structural code reusable to other projects (not solving the same problem all over again). And to make the main application less bloated and only contain domain specific code as much as possible.
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
#### The following features are available.
|
5
|
+
- Creates (create, read, update, destroy) action methods for resources.
|
6
|
+
- Has render helpers for API or socket responses. ex. Converting models to its designated serializer.
|
7
|
+
- Converts snake case request params (from js standard) to underscore params (ruby standard)
|
8
|
+
- Searches layer under app/searches. Usually used for form searches.
|
9
|
+
- Services layer under app/services. For single responsibility domain-specific logic code.
|
10
|
+
- Exception notifier and API error response handler.
|
11
|
+
|
12
|
+
## Basic Usage
|
13
|
+
#### Controllers
|
14
|
+
```ruby
|
15
|
+
# app/controllers
|
16
|
+
# create,show,update,destroy methods are available by default
|
17
|
+
class ProjectsController < Upframework::ResourcesController
|
18
|
+
# Example of broadcasting with a serialized object using ActionCables.
|
19
|
+
def udate
|
20
|
+
super do
|
21
|
+
channel = @project.user
|
22
|
+
broadcast_serialized(channel, resource: @project, event: "Project Updated")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Example of rendering serialized responsed. This is using fast_jsonapi serializer.
|
27
|
+
def custom_action
|
28
|
+
render_serialized @project
|
29
|
+
end
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
#### Searches
|
34
|
+
```ruby
|
35
|
+
#app/searches
|
36
|
+
class ProjectSearch < Upframework::BaseSearch
|
37
|
+
def post_initialize
|
38
|
+
@per_page = 10
|
39
|
+
@scope = Project.accessible_by(@current_ability)
|
40
|
+
end
|
41
|
+
|
42
|
+
def execute
|
43
|
+
# query logic here using scope object defined above
|
44
|
+
# by default results are paginated
|
45
|
+
end
|
46
|
+
end
|
47
|
+
```
|
48
|
+
```
|
49
|
+
#search api available in
|
50
|
+
/search?resource=Project&arg1=""&arg2=""
|
51
|
+
```
|
52
|
+
|
53
|
+
#### Services
|
54
|
+
```ruby
|
55
|
+
#app/services
|
56
|
+
class Project::SubmitService < Upframework::BaseService
|
57
|
+
def post_initialize(id:, **attrs)
|
58
|
+
@project = Project.find(id)
|
59
|
+
end
|
60
|
+
|
61
|
+
def execute
|
62
|
+
# put main logic here
|
63
|
+
# ...
|
64
|
+
project.save
|
65
|
+
end
|
66
|
+
|
67
|
+
def result
|
68
|
+
project
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
service = Project::SubmitService.run
|
73
|
+
service.result => <Project: Instance>
|
74
|
+
service.success? => true/false
|
75
|
+
```
|
76
|
+
|
77
|
+
#### Routes
|
78
|
+
```ruby
|
79
|
+
#config/routes
|
80
|
+
mount Upframework::Engine => /path
|
81
|
+
```
|
82
|
+
routes being available
|
83
|
+
```
|
84
|
+
GET /search
|
85
|
+
POST /services/:service_name
|
86
|
+
```
|
6
87
|
|
7
88
|
## Installation
|
8
89
|
Add this line to your application's Gemfile:
|
@@ -7,17 +7,24 @@ class Upframework::BaseSearch < Upframework::BaseService
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def query(field)
|
10
|
-
@model_scope = yield if
|
10
|
+
@model_scope = yield if field.present?
|
11
11
|
end
|
12
12
|
|
13
13
|
def paginate_scope
|
14
|
+
return if @model_scope.nil?
|
15
|
+
|
14
16
|
@model_scope = @model_scope.
|
15
17
|
page(@page || DEFAULT_PAGE).
|
16
18
|
per(@per_page || DEFAULT_PER_PAGE).
|
17
19
|
order(created_at: :desc)
|
18
20
|
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
module ExecuteWrapper
|
23
|
+
def execute
|
24
|
+
super
|
25
|
+
paginate_scope
|
26
|
+
end
|
22
27
|
end
|
28
|
+
|
29
|
+
include ExecuteWrapper
|
23
30
|
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.7
|
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-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|