exceptions-resource 0.0.2p07 → 0.0.2

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: 565b64cc3de39009cc01639f072387b43952d8d6
4
- data.tar.gz: 9dfa0a1cd9a56727b0960d2d36b113ec58f9b629
3
+ metadata.gz: c05b97145bdd642c52ad4ea34aa4d2e1fd095f96
4
+ data.tar.gz: 32d8ae24dd3f3a8905bca46130c053fbf864828a
5
5
  SHA512:
6
- metadata.gz: 2c9d40712df39460304f7f754617a7d145970028c978e5a0b8f03a9b2e664d0524a44c7650d34d1afdf377104ff891f9eb5a2ae4ce0a2b336b7aa6ae18501763
7
- data.tar.gz: 9fd2031d9e50661c069d61f723a082d6e73df1cc8f0eb203e7ad0b506ee77973d679713d27a27cf96148de23f42b4a8bfaece09278602ecd55c8fa75a829dd14
6
+ metadata.gz: 1b47d81e51c087613c8218d7ee0fedbed69da2736a715fa6ba1781152566f85c53097469a7e1cc5398b4301efba4dbe419ef8f2305751978711acebecbbd5d68
7
+ data.tar.gz: 1324894a2465f62b69000281648232b96194368c85fa4eddc48dacc6310c13ab010629e1851a8301828f6f986dd0f17fd917a5ac1786fe537384271d754fb64d
@@ -1,206 +1,8 @@
1
1
  module Exceptions
2
- class Base < StandardError
3
- attr_accessor :object, :type
4
-
5
- # starts a new instance with an object
6
- # @param [Object] object
7
- def initialize object
8
- self.object = object
9
- end
10
-
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
18
-
19
- # return if is as simple error
20
- # @return [Boolean]
21
- def simple?
22
- self.class.name.demodulize.tableize.singularize == "simple"
23
- end
24
-
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
31
-
32
- class Model < Base
33
- # for model errors this method build a hash with all necessary information
34
- # @return [String] json string
35
- def error
36
- self.is_nested? ? self.build_nested : self.build_normal
37
- end
38
-
39
- def build_nested
40
- {
41
- error: {
42
- model: self.nested_model.camelcase,
43
- field: "#{self.nested_model}[#{self.nested_attr}]",
44
- attribute: self.nested_attr,
45
- message: self.message,
46
- full_message: "#{self.nested_attr_human} #{self.message}"
47
- }
48
- }
49
- end
50
-
51
- def build_normal
52
- {
53
- error: {
54
- model: self.model.camelcase,
55
- field: "#{self.model}[#{self.attribute}]",
56
- attribute: self.attribute,
57
- message: self.message,
58
- full_message: "#{self.attribute_human} #{self.message}"
59
- }
60
- }
61
- end
62
-
63
- # return what model is
64
- # @return [String]
65
- def model
66
- self.object.class.name.demodulize.tableize.singularize.downcase
67
- end
68
-
69
- def attribute
70
- self.object.errors.first[0]
71
- end
72
-
73
- def model_human
74
- self.object.class.model_name.human.demodulize.tableize.singularize.downcase
75
- end
76
-
77
- def attribute_human
78
- self.object.class.human_attribute_name(self.object.errors.first[0])
79
- end
80
-
81
- # return the error message
82
- # @return [String]
83
- def message
84
- "#{self.object.errors.first[1]}"
85
- end
86
-
87
- def status
88
- 422
89
- end
90
-
91
- def is_nested?
92
- attribute = self.object.errors.first[0]
93
-
94
- if self.object.errors.first[0].to_s.split(".").size > 1
95
- self.object.respond_to?(attribute) ? false : true
96
- else
97
- false
98
- end
99
- end
100
-
101
- def nested_model
102
- self.object.errors.first[0].to_s.split(".").first.singularize.downcase
103
- end
104
-
105
- def nested_model_human
106
- self.nested_model.capitalize.constantize.model_name.human
107
- end
108
-
109
- def nested_attr
110
- self.object.errors.first[0].to_s.split(".").last
111
- end
112
-
113
- def nested_attr_human
114
- self.nested_model.capitalize.constantize.human_attribute_name(self.nested_attr)
115
- end
116
- end
117
-
118
- class Resource < Base
119
- # for standard errors this method build a hash
120
- # @return [String] json string
121
- def error
122
- {
123
- error: {
124
- model: self.object["model"],
125
- attribute: self.object["attribute"],
126
- field: self.object["field"],
127
- message: self.object["message"],
128
- full_message: "#{self.object["attribute"]} #{self.object["message"]}"
129
- }
130
- }
131
- end
132
-
133
- # return the error message
134
- # @return [String]
135
- def message
136
- self.error[:message]
137
- end
138
-
139
- # return the error status
140
- def status
141
- 406
142
- end
143
- end
144
-
145
- class Simple < Base
146
- attr_accessor :status
147
-
148
-
149
- # for standard errors this method build a hash
150
- # @return [String] json string
151
- def error
152
- {
153
- error: {
154
- message: self.object[:message],
155
- full_message: "#{self.object[:field]} #{self.object[:message]} ",
156
- field: self.object[:field]
157
- }
158
- }
159
- end
160
-
161
- # return the error message
162
- # @return [String]
163
- def message
164
- self.object[:message]
165
- end
166
-
167
- # return the error status
168
- def status
169
- 406
170
- end
171
- end
172
-
173
- # represents the simple errors
174
- class UnauthorizedApplication < Base
175
- attr_accessor :status
176
-
177
-
178
- # for standard errors this method build a hash
179
- # @return [String] json string
180
- def error
181
- {
182
- error: {
183
- message: self.object[:message]
184
- }
185
- }
186
- end
187
-
188
- # return the error message
189
- # @return [String]
190
- def message
191
- self.object[:message]
192
- end
193
-
194
- # return the error status
195
- def status
196
- 401
197
- end
198
-
199
- end
200
-
201
2
  end
202
3
 
203
- # require 'exceptions/model'
204
- # require 'exceptions/resource'
205
- # require 'exceptions/simple'
206
- # require 'exceptions/unauthorized_application'
4
+ require 'exceptions/base'
5
+ require 'exceptions/model'
6
+ require 'exceptions/resource'
7
+ require 'exceptions/simple'
8
+ require 'exceptions/unauthorized_application'
@@ -1,4 +1,5 @@
1
1
  class Exceptions::Model < Exceptions::Base
2
+
2
3
  # for model errors this method build a hash with all necessary information
3
4
  # @return [String] json string
4
5
  def error
@@ -82,4 +83,6 @@ class Exceptions::Model < Exceptions::Base
82
83
  def nested_attr_human
83
84
  self.nested_model.capitalize.constantize.human_attribute_name(self.nested_attr)
84
85
  end
86
+
87
+
85
88
  end
@@ -1,29 +1,31 @@
1
1
  # represents the simple errors
2
- class Exceptions::Simple < Exceptions::Base
3
- attr_accessor :status
2
+ module Exceptions
3
+ class Simple < Base
4
+ attr_accessor :status
4
5
 
6
+
7
+ # for standard errors this method build a hash
8
+ # @return [String] json string
9
+ def error
10
+ {
11
+ error: {
12
+ message: self.object[:message],
13
+ full_message: "#{self.object[:field]} #{self.object[:message]} ",
14
+ field: self.object[:field]
15
+ }
16
+ }
17
+ end
5
18
 
6
- # for standard errors this method build a hash
7
- # @return [String] json string
8
- def error
9
- {
10
- error: {
11
- message: self.object[:message],
12
- full_message: "#{self.object[:field]} #{self.object[:message]} ",
13
- field: self.object[:field]
14
- }
15
- }
16
- end
19
+ # return the error message
20
+ # @return [String]
21
+ def message
22
+ self.object[:message]
23
+ end
17
24
 
18
- # return the error message
19
- # @return [String]
20
- def message
21
- self.object[:message]
22
- end
25
+ # return the error status
26
+ def status
27
+ 406
28
+ end
23
29
 
24
- # return the error status
25
- def status
26
- 406
27
30
  end
28
-
29
31
  end
@@ -1,27 +1,29 @@
1
1
  # represents the simple errors
2
- class Exceptions::UnauthorizedApplication < Exceptions::Base
3
- attr_accessor :status
2
+ module Exceptions
3
+ class UnauthorizedApplication < Base
4
+ attr_accessor :status
4
5
 
6
+
7
+ # for standard errors this method build a hash
8
+ # @return [String] json string
9
+ def error
10
+ {
11
+ error: {
12
+ message: self.object[:message]
13
+ }
14
+ }
15
+ end
5
16
 
6
- # for standard errors this method build a hash
7
- # @return [String] json string
8
- def error
9
- {
10
- error: {
11
- message: self.object[:message]
12
- }
13
- }
14
- end
17
+ # return the error message
18
+ # @return [String]
19
+ def message
20
+ self.object[:message]
21
+ end
15
22
 
16
- # return the error message
17
- # @return [String]
18
- def message
19
- self.object[:message]
20
- end
23
+ # return the error status
24
+ def status
25
+ 401
26
+ end
21
27
 
22
- # return the error status
23
- def status
24
- 401
25
28
  end
26
-
27
29
  end
@@ -1,3 +1,3 @@
1
1
  module Exceptions
2
- VERSION = "0.0.2p07"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exceptions-resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2p07
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Douglas Rossignolli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-09 00:00:00.000000000 Z
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,9 +88,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  requirements:
91
- - - ">"
91
+ - - ">="
92
92
  - !ruby/object:Gem::Version
93
- version: 1.3.1
93
+ version: '0'
94
94
  requirements: []
95
95
  rubyforge_project:
96
96
  rubygems_version: 2.4.5