respo 0.2.0 → 0.2.1

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: 70b80dd1f2209be559e92b32045c584dd0e722da52bc9ba5e34f713a1876db3c
4
- data.tar.gz: f11fda7441276a0bd52b8d0eadd122322c0589684e749b7e3bfc1c13f41a0505
3
+ metadata.gz: 124bdd0f1d07fb4df64261ee5a24e4d0000a4bb96eae841271d338b2a1f0e6b2
4
+ data.tar.gz: f6d89bf03f5a15080384eed872cdb3b1e7d8e76ac062b4323ed72e64db8cc8e3
5
5
  SHA512:
6
- metadata.gz: d3c87ff90ee11deb6ed58285ed66459f7b50c407e506c538a1654440871af34296d3ef64f09184d4d3965bc598695151e2199e279b2a229dbb24f9aa084ff174
7
- data.tar.gz: f6851f696c6b2a951d1a96d2311bb0ff09229309cc2ae94e58e4ff0bff33dc70d364b6564ea47ee77265ab383ce6971ce345b61c7e14d60f699861fc47306d19
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
@@ -19,7 +19,6 @@ module Respo
19
19
 
20
20
  def initialize(record, **args)
21
21
  @record = record
22
- puts "Response record: #{record}"
23
22
 
24
23
  # NOTE: dynamically define instance variables
25
24
  args.each do |key, value|
@@ -13,12 +13,8 @@ module Respo
13
13
 
14
14
  def self.model_name(record)
15
15
  model_name = record&.class&.name
16
- wrapped = record.is_a?(Array) || record.is_a?(ActiveRecord::Relation)
17
- if wrapped
18
- record[0].class.name
19
- else
20
- model_name
21
- end
16
+ wrapped = record.is_a?(Array) || model_name == 'ActiveRecord::Relation'
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
@@ -3,9 +3,6 @@
3
3
  module Respo
4
4
  module Successes
5
5
  class Index < Respo::Successes::Base
6
- def initialize(record, view: nil, root: nil)
7
- super(record, view: view, root: root)
8
- end
9
6
  end
10
7
  end
11
8
  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.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
data/lib/respo.rb CHANGED
@@ -3,9 +3,7 @@
3
3
  require_relative 'respo/base'
4
4
 
5
5
  module Respo
6
- include Helpers
7
-
8
- def self.method_missing(method, record, **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)
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.2.0
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,6 +140,7 @@ 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