respo 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/lib/respo/base.rb +1 -1
- data/lib/respo/constants.rb +4 -0
- data/lib/respo/errors/base.rb +3 -1
- data/lib/respo/errors/show.rb +0 -3
- data/lib/respo/helpers.rb +20 -1
- data/lib/respo/response.rb +1 -1
- data/lib/respo/serializers/blueprinter.rb +3 -3
- data/lib/respo/{success → successes}/base.rb +2 -8
- data/lib/respo/{success → successes}/destroy.rb +2 -2
- data/lib/respo/{success → successes}/index.rb +2 -2
- data/lib/respo/{success → successes}/show.rb +2 -2
- data/lib/respo/{success → successes}/update.rb +2 -2
- data/lib/respo/version.rb +1 -1
- data/lib/respo.rb +11 -2
- metadata +6 -7
- data/lib/initializer.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81917378520ebf8e99b9c2a6d8fc62c0313061fcb19b5012f717583d9c3dacce
|
4
|
+
data.tar.gz: 322b6dd6752ace7b975c10d015a6978de7c551fca78a154cc610aeab091e7a92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23c3e46aa8da329a8f0e2d0953a5bfd3b22d76a4295373a79421815263c3af5a02d96c3b973f7bca3acb682dbf2e1a7a1bc8a58debb4e397743dca011ed1b3ef
|
7
|
+
data.tar.gz: 16678820b65275079e94021b0737f6fd03382f9bf15fce28ea468f8c90ff482c9788a969fed92406b701f1aa68f50b2c6ccf873099836949b95656e00a251ec7
|
data/Gemfile
CHANGED
data/lib/respo/base.rb
CHANGED
@@ -7,7 +7,7 @@ require_relative 'configuration'
|
|
7
7
|
require_relative 'respo_error'
|
8
8
|
require_relative 'serializers/blueprinter'
|
9
9
|
require_relative 'response'
|
10
|
-
require_relative '
|
10
|
+
require_relative 'successes/base'
|
11
11
|
require_relative 'errors/base'
|
12
12
|
|
13
13
|
module Respo
|
data/lib/respo/constants.rb
CHANGED
data/lib/respo/errors/base.rb
CHANGED
@@ -3,12 +3,14 @@
|
|
3
3
|
module Respo
|
4
4
|
module Errors
|
5
5
|
class Base < Response
|
6
|
+
include Helpers
|
7
|
+
|
6
8
|
def call
|
7
9
|
{ json: { errors: @record.errors.full_messages }, status: status_code }
|
8
10
|
end
|
9
11
|
|
10
12
|
def status_code
|
11
|
-
:
|
13
|
+
Respo::Constants::STATUSES.dig(action_name(self), :error).to_sym
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
data/lib/respo/errors/show.rb
CHANGED
data/lib/respo/helpers.rb
CHANGED
@@ -6,8 +6,27 @@ module Respo
|
|
6
6
|
str.split('_').collect(&:capitalize).join
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def model_name(record)
|
10
10
|
record.class.name.split('::').last
|
11
11
|
end
|
12
|
+
|
13
|
+
def action_name(action_class)
|
14
|
+
action_class.class.name.split('::').last.downcase.to_sym
|
15
|
+
end
|
16
|
+
|
17
|
+
# NOTE: only for successes and errors
|
18
|
+
def self.singularize(str)
|
19
|
+
{
|
20
|
+
errors: 'error',
|
21
|
+
successes: 'success'
|
22
|
+
}[str.to_sym] || str
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.pluralize(str)
|
26
|
+
{
|
27
|
+
error: 'errors',
|
28
|
+
success: 'successes'
|
29
|
+
}[str.to_sym] || str
|
30
|
+
end
|
12
31
|
end
|
13
32
|
end
|
data/lib/respo/response.rb
CHANGED
@@ -3,14 +3,14 @@
|
|
3
3
|
module Respo
|
4
4
|
module Serializers
|
5
5
|
module Blueprinter
|
6
|
-
include Helpers
|
6
|
+
include Respo::Helpers
|
7
7
|
|
8
8
|
def self.render(record, **args)
|
9
9
|
serializer_constant(record).render(record, **args)
|
10
10
|
end
|
11
11
|
|
12
|
-
def serializer_constant(record)
|
13
|
-
Object.const_get("#{model_name(record)}Blueprinter")
|
12
|
+
def self.serializer_constant(record)
|
13
|
+
Object.const_get("#{Respo::Helpers.model_name(record)}Blueprinter")
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
3
|
module Respo
|
6
|
-
module
|
4
|
+
module Successes
|
7
5
|
class Base < Response
|
8
6
|
def initialize(record, view: nil, root: nil)
|
9
7
|
super(record, view: view, root: root)
|
@@ -20,11 +18,7 @@ module Respo
|
|
20
18
|
end
|
21
19
|
|
22
20
|
def status_code
|
23
|
-
:
|
24
|
-
end
|
25
|
-
|
26
|
-
def action_name
|
27
|
-
this.class.name.split('::').last
|
21
|
+
Respo::Constants::STATUSES.dig(action_name(self), :success).to_sym
|
28
22
|
end
|
29
23
|
end
|
30
24
|
end
|
data/lib/respo/version.rb
CHANGED
data/lib/respo.rb
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'initializer'
|
4
3
|
require_relative 'respo/base'
|
5
4
|
|
6
5
|
module Respo
|
7
|
-
|
6
|
+
include Helpers
|
7
|
+
|
8
|
+
def self.method_missing(method, *args)
|
9
|
+
action, status = method.to_s.split('_')
|
10
|
+
|
11
|
+
return 'No Method' unless %w[success error].include?(status)
|
12
|
+
|
13
|
+
klass_name = "Respo::#{Helpers.pluralize(status).capitalize}::#{action.capitalize}"
|
14
|
+
klass = Object.const_get(klass_name)
|
15
|
+
klass.call(args)
|
16
|
+
end
|
8
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: respo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miko Dagatan
|
@@ -111,7 +111,6 @@ files:
|
|
111
111
|
- LICENSE.txt
|
112
112
|
- README.md
|
113
113
|
- Rakefile
|
114
|
-
- lib/initializer.rb
|
115
114
|
- lib/respo.rb
|
116
115
|
- lib/respo/base.rb
|
117
116
|
- lib/respo/configuration.rb
|
@@ -124,11 +123,11 @@ files:
|
|
124
123
|
- lib/respo/respo_error.rb
|
125
124
|
- lib/respo/response.rb
|
126
125
|
- lib/respo/serializers/blueprinter.rb
|
127
|
-
- lib/respo/
|
128
|
-
- lib/respo/
|
129
|
-
- lib/respo/
|
130
|
-
- lib/respo/
|
131
|
-
- lib/respo/
|
126
|
+
- lib/respo/successes/base.rb
|
127
|
+
- lib/respo/successes/destroy.rb
|
128
|
+
- lib/respo/successes/index.rb
|
129
|
+
- lib/respo/successes/show.rb
|
130
|
+
- lib/respo/successes/update.rb
|
132
131
|
- lib/respo/version.rb
|
133
132
|
- sig/respo.rbs
|
134
133
|
homepage: https://rubygems.org/gems/respo
|
data/lib/initializer.rb
DELETED