exceptions-resource 0.0.1p01 → 0.0.2p01

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
  SHA1:
3
- metadata.gz: 2002338e27658b3366f4bd4748244ee7de86dd70
4
- data.tar.gz: 429c9c169ca6c43149f66101b89ed7b0e89309c9
3
+ metadata.gz: 971078a4e0ce20ab029da61fc524539fd749058d
4
+ data.tar.gz: 8597a9572f35b160c54786854d8f17a3d6f1bf76
5
5
  SHA512:
6
- metadata.gz: bd27f05adbee686ebac0dcd257b1f33745142e163c1ad7006ac2996a0bfbc76d3bd23cef3579e82f23d52a189ee403cb97ecd94102b949c6d53375d35e4f857c
7
- data.tar.gz: 83e5a14e3a37026d95b1af57ffb488e047e0e2fe82cf9d4de41b2ecb3fd46c15af6688c4923f949a52557d144b77cb46bc5882b5f9d5711a79ffe87d37b56e22
6
+ metadata.gz: a942f17789d19bb10f27a5e7af9476cbe44b23a4451e22459b9bb715ee8ba7121fd102700865d136f8c51f26ab3e8192bf404d96d448cd0213b8116b0db80e2c
7
+ data.tar.gz: d40a27f0a5dfcabab54bc3af91e0ffd9aec2d84e7e5bbfcd788b836472d03485d1b93088f3ab11c59d44cae1a62e09f1128eae5de79460ae68ac080fe66db139
data/README.md CHANGED
@@ -8,7 +8,11 @@ needs `ActiveModel` as dependency if you aren't working with rails.
8
8
  Add this line to your application's Gemfile:
9
9
 
10
10
  ```ruby
11
- gem 'exceptions', github: 'xdougx/exceptions'
11
+ # direct from github
12
+ gem 'exceptions-resource', github: 'xdougx/exceptions-resource'
13
+
14
+ # from rubygems
15
+ gem 'exceptions-resource'
12
16
  ```
13
17
 
14
18
  And then execute:
@@ -17,7 +21,7 @@ And then execute:
17
21
 
18
22
  Or install it yourself as:
19
23
 
20
- $ gem install exceptions
24
+ $ gem install exceptions-resource
21
25
 
22
26
  ## Usage
23
27
 
@@ -1,29 +1,31 @@
1
- class Exceptions::Base < StandardError
2
- attr_accessor :object, :type
1
+ module Exceptions
2
+ class Base < StandardError
3
+ attr_accessor :object, :type
3
4
 
4
- # starts a new instance with an object
5
- # @param [Object] object
6
- def initialize object
7
- self.object = object
8
- end
5
+ # starts a new instance with an object
6
+ # @param [Object] object
7
+ def initialize object
8
+ self.object = object
9
+ end
9
10
 
10
- # standard error for Models
11
- # @param [ActiveRecord::Base] object
12
- # @return [Exceptions::Base]
13
- def self.build object
14
- exception = new object
15
- return exception
16
- end
11
+ # standard error for Models
12
+ # @param [ActiveRecord::Base] object
13
+ # @return [Exceptions::Base]
14
+ def self.build object
15
+ exception = new object
16
+ return exception
17
+ end
17
18
 
18
- # return if is as simple error
19
- # @return [Boolean]
20
- def simple?
21
- self.class.name.demodulize.tableize.singularize == "simple"
22
- end
19
+ # return if is as simple error
20
+ # @return [Boolean]
21
+ def simple?
22
+ self.class.name.demodulize.tableize.singularize == "simple"
23
+ end
23
24
 
24
- # return if is as model error
25
- # @return [Boolean]
26
- def model?
27
- self.class.name.demodulize.tableize.singularize == "model"
28
- end
25
+ # return if is as model error
26
+ # @return [Boolean]
27
+ def model?
28
+ self.class.name.demodulize.tableize.singularize == "model"
29
+ end
30
+ end
29
31
  end
@@ -1,88 +1,87 @@
1
- class Exceptions::Model < Exceptions::Base
2
-
3
- # for model errors this method build a hash with all necessary information
4
- # @return [String] json string
5
- def error
6
- self.is_nested? ? self.build_nested : self.build_normal
7
- end
1
+ module Exceptions
2
+ class Model < Base
3
+ # for model errors this method build a hash with all necessary information
4
+ # @return [String] json string
5
+ def error
6
+ self.is_nested? ? self.build_nested : self.build_normal
7
+ end
8
8
 
9
- def build_nested
10
- {
11
- error: {
12
- model: self.nested_model.camelcase,
13
- field: "#{self.nested_model}[#{self.nested_attr}]",
14
- attribute: self.nested_attr,
15
- message: self.message,
16
- full_message: "#{self.nested_attr_human} #{self.message}"
17
- }
18
- }
19
- end
9
+ def build_nested
10
+ {
11
+ error: {
12
+ model: self.nested_model.camelcase,
13
+ field: "#{self.nested_model}[#{self.nested_attr}]",
14
+ attribute: self.nested_attr,
15
+ message: self.message,
16
+ full_message: "#{self.nested_attr_human} #{self.message}"
17
+ }
18
+ }
19
+ end
20
20
 
21
- def build_normal
22
- {
23
- error: {
24
- model: self.model.camelcase,
25
- field: "#{self.model}[#{self.attribute}]",
26
- attribute: self.attribute,
27
- message: self.message,
28
- full_message: "#{self.attribute_human} #{self.message}"
29
- }
30
- }
31
- end
21
+ def build_normal
22
+ {
23
+ error: {
24
+ model: self.model.camelcase,
25
+ field: "#{self.model}[#{self.attribute}]",
26
+ attribute: self.attribute,
27
+ message: self.message,
28
+ full_message: "#{self.attribute_human} #{self.message}"
29
+ }
30
+ }
31
+ end
32
32
 
33
- # return what model is
34
- # @return [String]
35
- def model
36
- self.object.class.name.demodulize.tableize.singularize.downcase
37
- end
33
+ # return what model is
34
+ # @return [String]
35
+ def model
36
+ self.object.class.name.demodulize.tableize.singularize.downcase
37
+ end
38
38
 
39
- def attribute
40
- self.object.errors.first[0]
41
- end
39
+ def attribute
40
+ self.object.errors.first[0]
41
+ end
42
42
 
43
- def model_human
44
- self.object.class.model_name.human.demodulize.tableize.singularize.downcase
45
- end
43
+ def model_human
44
+ self.object.class.model_name.human.demodulize.tableize.singularize.downcase
45
+ end
46
46
 
47
- def attribute_human
48
- self.object.class.human_attribute_name(self.object.errors.first[0])
49
- end
47
+ def attribute_human
48
+ self.object.class.human_attribute_name(self.object.errors.first[0])
49
+ end
50
50
 
51
- # return the error message
52
- # @return [String]
53
- def message
54
- "#{self.object.errors.first[1]}"
55
- end
51
+ # return the error message
52
+ # @return [String]
53
+ def message
54
+ "#{self.object.errors.first[1]}"
55
+ end
56
56
 
57
- def status
58
- :unprocessable_entity
59
- end
57
+ def status
58
+ 422
59
+ end
60
60
 
61
- def is_nested?
62
- attribute = self.object.errors.first[0]
61
+ def is_nested?
62
+ attribute = self.object.errors.first[0]
63
63
 
64
- if self.object.errors.first[0].to_s.split(".").size > 1
65
- self.object.respond_to?(attribute) ? false : true
66
- else
67
- false
64
+ if self.object.errors.first[0].to_s.split(".").size > 1
65
+ self.object.respond_to?(attribute) ? false : true
66
+ else
67
+ false
68
+ end
68
69
  end
69
- end
70
70
 
71
- def nested_model
72
- self.object.errors.first[0].to_s.split(".").first.singularize.downcase
73
- end
71
+ def nested_model
72
+ self.object.errors.first[0].to_s.split(".").first.singularize.downcase
73
+ end
74
74
 
75
- def nested_model_human
76
- self.nested_model.capitalize.constantize.model_name.human
77
- end
75
+ def nested_model_human
76
+ self.nested_model.capitalize.constantize.model_name.human
77
+ end
78
78
 
79
- def nested_attr
80
- self.object.errors.first[0].to_s.split(".").last
81
- end
79
+ def nested_attr
80
+ self.object.errors.first[0].to_s.split(".").last
81
+ end
82
82
 
83
- def nested_attr_human
84
- self.nested_model.capitalize.constantize.human_attribute_name(self.nested_attr)
83
+ def nested_attr_human
84
+ self.nested_model.capitalize.constantize.human_attribute_name(self.nested_attr)
85
+ end
85
86
  end
86
-
87
-
88
87
  end
@@ -1,26 +1,28 @@
1
- class Exceptions::Resource < Exceptions::Base
2
- # for standard errors this method build a hash
3
- # @return [String] json string
4
- def error
5
- {
6
- error: {
7
- model: self.object["model"],
8
- attribute: self.object["attribute"],
9
- field: self.object["field"],
10
- message: self.object["message"],
11
- full_message: "#{self.object["attribute"]} #{self.object["message"]}"
12
- }
13
- }
14
- end
1
+ module Exceptions
2
+ class Resource < Base
3
+ # for standard errors this method build a hash
4
+ # @return [String] json string
5
+ def error
6
+ {
7
+ error: {
8
+ model: self.object["model"],
9
+ attribute: self.object["attribute"],
10
+ field: self.object["field"],
11
+ message: self.object["message"],
12
+ full_message: "#{self.object["attribute"]} #{self.object["message"]}"
13
+ }
14
+ }
15
+ end
15
16
 
16
- # return the error message
17
- # @return [String]
18
- def message
19
- self.error[:message]
20
- end
17
+ # return the error message
18
+ # @return [String]
19
+ def message
20
+ self.error[:message]
21
+ end
21
22
 
22
- # return the error status
23
- def status
24
- :not_acceptable
23
+ # return the error status
24
+ def status
25
+ 406
26
+ end
25
27
  end
26
28
  end
@@ -24,7 +24,7 @@ module Exceptions
24
24
 
25
25
  # return the error status
26
26
  def status
27
- :not_acceptable
27
+ 406
28
28
  end
29
29
 
30
30
  end
@@ -22,7 +22,7 @@ module Exceptions
22
22
 
23
23
  # return the error status
24
24
  def status
25
- :unauthorized
25
+ 401
26
26
  end
27
27
 
28
28
  end
@@ -1,3 +1,3 @@
1
1
  module Exceptions
2
- VERSION = "0.0.1p01"
2
+ VERSION = "0.0.2p01"
3
3
  end
data/lib/exceptions.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  module Exceptions
2
2
  end
3
+
3
4
  require 'exceptions/base'
4
5
  require 'exceptions/model'
5
6
  require 'exceptions/resource'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exceptions-resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1p01
4
+ version: 0.0.2p01
5
5
  platform: ruby
6
6
  authors:
7
7
  - Douglas Rossignolli