respo 0.1.8 → 0.2.1

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: a674de07245a69c9df6c1948445db2c42f6cb403057de115a97f7f00c5d02620
4
- data.tar.gz: '0872dfb935c053cd10e49bf9b6f01361445607e62b9364a7f1963a7408cd8e33'
3
+ metadata.gz: 124bdd0f1d07fb4df64261ee5a24e4d0000a4bb96eae841271d338b2a1f0e6b2
4
+ data.tar.gz: f6d89bf03f5a15080384eed872cdb3b1e7d8e76ac062b4323ed72e64db8cc8e3
5
5
  SHA512:
6
- metadata.gz: 2d4e26599ef8abbbff101c0b9a6823ff565105bce8f23cf0557ab5c172d1cb84ec8126565767aaf69e00898de3343eeee206df670268342859063d13b0df5e9a
7
- data.tar.gz: db0292139fac5a5cc1e5b3b36bbabb6f77bfbdf2e71caa0d286785e03eb86e30f2abf581671e7d73eaf352ea7126896625c17fb38848a8fe26a1bc09665813d1
6
+ metadata.gz: d57229bdc8f4c418d6f447e1e5249bc58b1d788ddf8449d55b6605125999a433dec001a66f2c4b1b524e3a416f6fb49a02794ca708e0d6c277e7ea240fc734de
7
+ data.tar.gz: bf01bbf0cce1ce30d2b07ef86d12b88435b0ccb3ce7c5da00fd0c8912e46962262a1a91c13713d228adc4f09ac290a7b9d9527cce48b5b93a41406a53a18756a
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- respo (0.1.6)
4
+ respo (0.2.0)
5
+ activerecord
5
6
  blueprinter
6
7
 
7
8
  GEM
@@ -16,6 +16,8 @@ module Respo
16
16
  end
17
17
  end
18
18
 
19
+ require_relative 'index'
19
20
  require_relative 'show'
21
+ require_relative 'create'
20
22
  require_relative 'update'
21
23
  require_relative 'destroy'
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Respo
4
+ module Errors
5
+ class Create < Respo::Errors::Base
6
+ end
7
+ end
8
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Respo
4
4
  module Errors
5
- class Show < Respo::Errors::Base
5
+ class Destroy < Respo::Errors::Base
6
6
  end
7
7
  end
8
8
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Respo
4
+ module Errors
5
+ class Index < Respo::Errors::Base
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RespoError
2
4
  class RespoError < StandardError; end
3
5
  end
@@ -7,7 +7,7 @@ module Respo
7
7
  extend Forwardable
8
8
  include Helpers
9
9
 
10
- attr_reader :record
10
+ attr_reader :record, :view, :root
11
11
 
12
12
  def_delegators :serializer, :render
13
13
 
@@ -12,13 +12,9 @@ module Respo
12
12
  end
13
13
 
14
14
  def self.model_name(record)
15
- model_name = record.class.name
15
+ model_name = record&.class&.name
16
16
  wrapped = record.is_a?(Array) || model_name == 'ActiveRecord::Relation'
17
- if wrapped
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
@@ -3,8 +3,10 @@
3
3
  module Respo
4
4
  module Successes
5
5
  class Base < Response
6
- def initialize(record, view: nil, root: nil)
7
- super(record, view: view, root: root)
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'
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Respo
4
+ module Successes
5
+ class Create < Respo::Successes::Base
6
+ end
7
+ end
8
+ end
@@ -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} #{record}"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Respo
4
- VERSION = '0.1.8'
4
+ VERSION = '0.2.1'
5
5
  end
data/lib/respo.rb CHANGED
@@ -3,15 +3,13 @@
3
3
  require_relative 'respo/base'
4
4
 
5
5
  module Respo
6
- include Helpers
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.8
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