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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5dc4e38225f1091ec9ededb3e0403156c9806a95e0b23c22c03169a030fda1b
4
- data.tar.gz: 68be508da24fb695aea2029b0ac78cf0dfb5408ee3d8c3997fb67caf921a7698
3
+ metadata.gz: 56bea5267caba929195f4ff4692e20b9d82fa351fdb1817b3b104097e8e4f820
4
+ data.tar.gz: 9af1be007b1c7fa9555c58bb285f747f0a6130ba54185c2133a3d629a65fe3bd
5
5
  SHA512:
6
- metadata.gz: dc9e6fc1fa2df5b5f710a755bf5814e787d06f16c5792fcefaa8339940bdd73dc50eb72e25ca73ee7a2710085ce2472c65f15be4b89dcef13fdce09b61db6aae
7
- data.tar.gz: 43d03176e6695273b2216b214d5730f59de656b19dba481fd44e1eb2da78216397db2e9dfeeb032bcb07a729d0ffdd788420080cb0f8720d9de25132344a93c6
6
+ metadata.gz: 39c6363e11e759b624d708c43746b7c6bc932303cdd707a68dfab54df484794fb805db17a7beb2a09a48adc533d24be93c3afc50f850af2aadd19250c4a03cdb
7
+ data.tar.gz: f9fba79249385101c923241637c772a0e44b057223c71e30ae9af2ab9e9014601f7dd32c73f9fa5c8edf01a1c2dfbcb028fe3e1f68fc4028c4acb0140565f135
data/README.md CHANGED
@@ -1,8 +1,89 @@
1
1
  # Upframework
2
- Short description and motivation.
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
- ## Usage
5
- How to use my plugin.
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 present_value?(field)
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
- def present_value?(field)
21
- instance_variable_get("@#{field}").present?
22
+ module ExecuteWrapper
23
+ def execute
24
+ super
25
+ paginate_scope
26
+ end
22
27
  end
28
+
29
+ include ExecuteWrapper
23
30
  end
@@ -1,3 +1,3 @@
1
1
  module Upframework
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.7'
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.1
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-04-16 00:00:00.000000000 Z
11
+ date: 2020-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails