respo 0.1.8 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -1
- data/lib/respo/errors/base.rb +2 -0
- data/lib/respo/errors/create.rb +8 -0
- data/lib/respo/errors/destroy.rb +1 -1
- data/lib/respo/errors/index.rb +8 -0
- data/lib/respo/respo_error.rb +2 -0
- data/lib/respo/response.rb +1 -1
- data/lib/respo/serializers/blueprinter.rb +2 -6
- data/lib/respo/successes/base.rb +16 -2
- data/lib/respo/successes/create.rb +8 -0
- data/lib/respo/successes/destroy.rb +1 -5
- data/lib/respo/version.rb +1 -1
- data/lib/respo.rb +2 -4
- metadata +4 -4
- data/respo-0.1.5.gem +0 -0
- data/respo-0.1.6.gem +0 -0
- data/respo-0.1.7.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 124bdd0f1d07fb4df64261ee5a24e4d0000a4bb96eae841271d338b2a1f0e6b2
|
4
|
+
data.tar.gz: f6d89bf03f5a15080384eed872cdb3b1e7d8e76ac062b4323ed72e64db8cc8e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d57229bdc8f4c418d6f447e1e5249bc58b1d788ddf8449d55b6605125999a433dec001a66f2c4b1b524e3a416f6fb49a02794ca708e0d6c277e7ea240fc734de
|
7
|
+
data.tar.gz: bf01bbf0cce1ce30d2b07ef86d12b88435b0ccb3ce7c5da00fd0c8912e46962262a1a91c13713d228adc4f09ac290a7b9d9527cce48b5b93a41406a53a18756a
|
data/Gemfile.lock
CHANGED
data/lib/respo/errors/base.rb
CHANGED
data/lib/respo/errors/destroy.rb
CHANGED
data/lib/respo/respo_error.rb
CHANGED
data/lib/respo/response.rb
CHANGED
@@ -12,13 +12,9 @@ module Respo
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.model_name(record)
|
15
|
-
model_name =
|
15
|
+
model_name = record&.class&.name
|
16
16
|
wrapped = record.is_a?(Array) || model_name == 'ActiveRecord::Relation'
|
17
|
-
|
18
|
-
record[0].class.name
|
19
|
-
else
|
20
|
-
model_name
|
21
|
-
end
|
17
|
+
wrapped ? record[0].class.name : model_name
|
22
18
|
end
|
23
19
|
end
|
24
20
|
end
|
data/lib/respo/successes/base.rb
CHANGED
@@ -3,8 +3,10 @@
|
|
3
3
|
module Respo
|
4
4
|
module Successes
|
5
5
|
class Base < Response
|
6
|
-
|
7
|
-
|
6
|
+
attr_reader :label
|
7
|
+
|
8
|
+
def initialize(record, view: nil, root: nil, label: nil)
|
9
|
+
super(record, view: view, root: root, label: label)
|
8
10
|
end
|
9
11
|
|
10
12
|
def call
|
@@ -20,11 +22,23 @@ module Respo
|
|
20
22
|
def status_code
|
21
23
|
Respo::Constants::STATUSES.dig(action_name(self), :success).to_sym
|
22
24
|
end
|
25
|
+
|
26
|
+
def record_name
|
27
|
+
%w[name label title].each do |attr|
|
28
|
+
return record.send(attr) if record.respond_to?(attr)
|
29
|
+
end
|
30
|
+
'No Record Name'
|
31
|
+
end
|
32
|
+
|
33
|
+
def clean_label
|
34
|
+
record.class.name.split('::')
|
35
|
+
end
|
23
36
|
end
|
24
37
|
end
|
25
38
|
end
|
26
39
|
|
27
40
|
require_relative 'index'
|
28
41
|
require_relative 'show'
|
42
|
+
require_relative 'create'
|
29
43
|
require_relative 'update'
|
30
44
|
require_relative 'destroy'
|
@@ -4,11 +4,7 @@ module Respo
|
|
4
4
|
module Successes
|
5
5
|
class Destroy < Respo::Successes::Base
|
6
6
|
def data
|
7
|
-
"Deleted #{record_name} #{
|
8
|
-
end
|
9
|
-
|
10
|
-
def record_name
|
11
|
-
record.name || record.title || record.label
|
7
|
+
"Deleted #{record_name} #{label || clean_label}"
|
12
8
|
end
|
13
9
|
end
|
14
10
|
end
|
data/lib/respo/version.rb
CHANGED
data/lib/respo.rb
CHANGED
@@ -3,15 +3,13 @@
|
|
3
3
|
require_relative 'respo/base'
|
4
4
|
|
5
5
|
module Respo
|
6
|
-
|
7
|
-
|
8
|
-
def self.method_missing(method, *args)
|
6
|
+
def self.method_missing(method, record, **args) # rubocop:disable Style/MissingRespondToMissing
|
9
7
|
action, status = method.to_s.split('_')
|
10
8
|
|
11
9
|
return 'No Method' unless %w[success error].include?(status)
|
12
10
|
|
13
11
|
klass_name = "Respo::#{Helpers.pluralize(status).capitalize}::#{action.capitalize}"
|
14
12
|
klass = Object.const_get(klass_name)
|
15
|
-
klass.call(args)
|
13
|
+
klass.call(record, **args)
|
16
14
|
end
|
17
15
|
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.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miko Dagatan
|
@@ -130,7 +130,9 @@ files:
|
|
130
130
|
- lib/respo/configuration.rb
|
131
131
|
- lib/respo/constants.rb
|
132
132
|
- lib/respo/errors/base.rb
|
133
|
+
- lib/respo/errors/create.rb
|
133
134
|
- lib/respo/errors/destroy.rb
|
135
|
+
- lib/respo/errors/index.rb
|
134
136
|
- lib/respo/errors/show.rb
|
135
137
|
- lib/respo/errors/update.rb
|
136
138
|
- lib/respo/helpers.rb
|
@@ -138,14 +140,12 @@ files:
|
|
138
140
|
- lib/respo/response.rb
|
139
141
|
- lib/respo/serializers/blueprinter.rb
|
140
142
|
- lib/respo/successes/base.rb
|
143
|
+
- lib/respo/successes/create.rb
|
141
144
|
- lib/respo/successes/destroy.rb
|
142
145
|
- lib/respo/successes/index.rb
|
143
146
|
- lib/respo/successes/show.rb
|
144
147
|
- lib/respo/successes/update.rb
|
145
148
|
- lib/respo/version.rb
|
146
|
-
- respo-0.1.5.gem
|
147
|
-
- respo-0.1.6.gem
|
148
|
-
- respo-0.1.7.gem
|
149
149
|
- sig/respo.rbs
|
150
150
|
homepage: https://rubygems.org/gems/respo
|
151
151
|
licenses:
|
data/respo-0.1.5.gem
DELETED
Binary file
|
data/respo-0.1.6.gem
DELETED
Binary file
|
data/respo-0.1.7.gem
DELETED
Binary file
|