error 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (9) hide show
  1. data/Gemfile +3 -0
  2. data/Guardfile +11 -0
  3. data/LICENSE +20 -0
  4. data/README.md +32 -0
  5. data/Rakefile +60 -0
  6. data/VERSION +1 -0
  7. data/examples/simple.rb +54 -0
  8. data/lib/error.rb +25 -0
  9. metadata +240 -0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1,11 @@
1
+ guard 'yard' do
2
+ watch(%r{app/.+\.rb})
3
+ watch(%r{lib/.+\.rb})
4
+ watch(%r{ext/.+\.c})
5
+ end
6
+
7
+ guard 'rspec', cli: '-c -f Fuubar' do
8
+ watch(%r{^spec/.+_spec\.rb$})
9
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
10
+ watch('spec/spec_helper.rb') { "spec" }
11
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Ryan Scott Lewis <ryan@rynet.us>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ # Error
2
+
3
+ `Error` is a very small library that serves as a base `Class` for error `Class`es within your
4
+ application.
5
+
6
+ ## Install
7
+
8
+ ### Bundler: `gem 'error'`
9
+
10
+ ### RubyGems: `gem install error`
11
+
12
+ ## Usage
13
+
14
+ ```ruby
15
+
16
+ ```
17
+
18
+ ## Contributing
19
+
20
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
21
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
22
+ * Fork the project
23
+ * Start a feature/bugfix branch
24
+ * Commit and push until you are happy with your contribution
25
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
26
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
27
+
28
+ ## Copyright
29
+
30
+ Copyright © 2012 Ryan Scott Lewis <ryan@rynet.us>.
31
+
32
+ The MIT License (MIT) - See LICENSE for further details.
@@ -0,0 +1,60 @@
1
+ require 'pathname'
2
+
3
+ def require_task(path)
4
+ begin
5
+ require path
6
+
7
+ yield
8
+ rescue LoadError
9
+ puts '', "Could not load '#{path}'.", 'Try to `rake gem:spec` and `bundle install` and try again.', ''
10
+ end
11
+ end
12
+
13
+ spec = Gem::Specification.new do |s|
14
+
15
+ # Variables
16
+ s.name = 'error'
17
+ s.author = 'Ryan Scott Lewis'
18
+ s.email = 'ryan@rynet.us'
19
+ s.summary = 'A base class for error classes witin your application.'
20
+ s.post_install_message = "NOTICE: `#{s.name}` is a placeholder gem. Check back with this gem has a MINOR version."
21
+
22
+ # Dependencies
23
+ s.add_dependency 'version', '~> 1.0.0'
24
+ s.add_development_dependency 'activesupport', '~> 3'
25
+ s.add_development_dependency 'guard-rspec', '~> 2.1'
26
+ s.add_development_dependency 'guard-yard', '~> 2.0'
27
+ s.add_development_dependency 'rb-fsevent', '~> 0.9'
28
+ s.add_development_dependency 'fuubar', '~> 1.1'
29
+ s.add_development_dependency 'redcarpet', '~> 2.2.2'
30
+ s.add_development_dependency 'github-markup', '~> 0.7'
31
+
32
+ # Pragmatically set variables
33
+ s.homepage = "http://github.com/RyanScottLewis/#{s.name}"
34
+ s.version = Pathname.glob('VERSION*').first.read
35
+ s.description = Pathname.glob('README*').first.read
36
+ s.require_paths = ['lib']
37
+ s.files = `git ls-files`.lines.to_a.collect { |s| s.strip }
38
+ s.executables = `git ls-files -- bin/*`.lines.to_a.collect { |s| File.basename(s.strip) }
39
+
40
+ end
41
+
42
+ desc 'Generate the gemspec defined in this Rakefile'
43
+ task :gemspec do
44
+ Pathname.new("#{spec.name}.gemspec").open('w') { |f| f.write(spec.to_ruby) }
45
+ end
46
+
47
+ require_task 'rake/version_task' do
48
+ Rake::VersionTask.new do |t|
49
+ t.with_git_tag = true
50
+ t.with_gemspec = spec
51
+ end
52
+ end
53
+
54
+ require 'rubygems/package_task'
55
+ Gem::PackageTask.new(spec) do |t|
56
+ t.need_zip = false
57
+ t.need_tar = false
58
+ end
59
+
60
+ task :default => :gemspec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,54 @@
1
+ require 'error'
2
+
3
+ module MyApp
4
+
5
+ # Define the that MyApp has an `Error`.
6
+ # This makes it very easy to see if an exception came from your application what-so-ever.
7
+ #
8
+ # This will define the `MyApp::Error` constant that is a `Class` that subclasses `::Error`.
9
+ has_error
10
+
11
+ # Define `Myapp::IntegerConversionError` class with a String (or anything responding to `to_s`).
12
+ #
13
+ # This will add constant `IntegerConversionError` that subclasses `MyApp::Error`.
14
+ has_error 'IntegerConversionError'
15
+
16
+ # Define with a Symbol (or anything responding to `to_sym`).
17
+ # If the given Object does not respond to `to_s`, it then checks to see if it responds to
18
+ # `to_sym`. If it does, it simply converts the Object to a Symbol, then to a String using `to_s`.
19
+ # When you pass the `message` option, it will be returned when you call `Error#to_s`.
20
+ #
21
+ # Defines 'StringConversionError' that is a `Class` that subclasses `MyApp::Error`.
22
+ has_error :string_conversion do |error|
23
+ error.message { "`#@target` is not a String or does not respond to #to_s." }
24
+ end
25
+
26
+ # Define with a Hash (or anything responding to `to_h`).
27
+ # Both the key and the value conform to the above rules.
28
+ #
29
+ # Defines 'InvalidEmailError' that is a `Class` that subclasses `MyApp::StringConversionError`.
30
+ has_error 'invalid_email' => StringConversionError do |e|
31
+ e.message { "email is not a valid email address." }
32
+ end
33
+
34
+ # Advanced usage.
35
+ has_error invalid_gender: 'String Conversion' do |e|
36
+ e.message { "#{@target || 'gender'} must be either `male` or `female`." }
37
+ e.unless { "#{@target || 'gender'} must be either `male` or `female`." }
38
+ end
39
+
40
+ class User
41
+ def initialize(name, email, age, gender)
42
+ # Raise error in a normal fashion.
43
+ # The argument must be a `Hash`, subclass of `Hash`, or respond to `to_hash`, ot `to_h`.
44
+ #
45
+ # All options passed to the `Hash` will be defined as instance variables on the instance of
46
+ # the `Error` instance before the `message`, `if`, and `unless` `Proc`s are `instance_eval`'d
47
+ # on the `Error` instance.
48
+ raise StringConversionError, target: :name unless name.is_a?(String) || name.respond_to?(:string)
49
+
50
+ raise InvalidEmailError, email: emai
51
+ fail :invalid_gender, gender: gender
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,25 @@
1
+ require 'version'
2
+
3
+ # A base class for Error classes in your application.
4
+ class Error < StandardError
5
+
6
+ is_versioned
7
+
8
+ # The target of the error.
9
+ attr_accessor :target
10
+
11
+ # @param target The target of the error.
12
+ def initialize(target=nil)
13
+ @target = target
14
+ end
15
+
16
+ # The String to print.
17
+ #
18
+ # @return [String]
19
+ def to_s
20
+ @target.to_s
21
+ end
22
+
23
+ end
24
+
25
+ require 'error/import'
metadata ADDED
@@ -0,0 +1,240 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: error
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Scott Lewis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: version
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: guard-rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.1'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.1'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-yard
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rb-fsevent
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '0.9'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '0.9'
94
+ - !ruby/object:Gem::Dependency
95
+ name: fuubar
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '1.1'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '1.1'
110
+ - !ruby/object:Gem::Dependency
111
+ name: redcarpet
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 2.2.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 2.2.2
126
+ - !ruby/object:Gem::Dependency
127
+ name: github-markup
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: '0.7'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: '0.7'
142
+ description: ! '# Error
143
+
144
+
145
+ `Error` is a very small library that serves as a base `Class` for error `Class`es
146
+ within your
147
+
148
+ application.
149
+
150
+
151
+ ## Install
152
+
153
+
154
+ ### Bundler: `gem ''error''`
155
+
156
+
157
+ ### RubyGems: `gem install error`
158
+
159
+
160
+ ## Usage
161
+
162
+
163
+ ```ruby
164
+
165
+
166
+ ```
167
+
168
+
169
+ ## Contributing
170
+
171
+
172
+ * Check out the latest master to make sure the feature hasn''t been implemented
173
+ or the bug hasn''t been fixed yet
174
+
175
+ * Check out the issue tracker to make sure someone already hasn''t requested it
176
+ and/or contributed it
177
+
178
+ * Fork the project
179
+
180
+ * Start a feature/bugfix branch
181
+
182
+ * Commit and push until you are happy with your contribution
183
+
184
+ * Make sure to add tests for it. This is important so I don''t break it in a future
185
+ version unintentionally.
186
+
187
+ * Please try not to mess with the Rakefile, version, or history. If you want to
188
+ have your own version, or is otherwise necessary, that is fine, but please isolate
189
+ to its own commit so I can cherry-pick around it.
190
+
191
+
192
+ ## Copyright
193
+
194
+
195
+ Copyright © 2012 Ryan Scott Lewis <ryan@rynet.us>.
196
+
197
+
198
+ The MIT License (MIT) - See LICENSE for further details.'
199
+ email: ryan@rynet.us
200
+ executables: []
201
+ extensions: []
202
+ extra_rdoc_files: []
203
+ files:
204
+ - Gemfile
205
+ - Guardfile
206
+ - LICENSE
207
+ - README.md
208
+ - Rakefile
209
+ - VERSION
210
+ - examples/simple.rb
211
+ - lib/error.rb
212
+ homepage: http://github.com/RyanScottLewis/error
213
+ licenses: []
214
+ post_install_message: ! 'NOTICE: `error` is a placeholder gem. Check back with this
215
+ gem has a MINOR version.'
216
+ rdoc_options: []
217
+ require_paths:
218
+ - lib
219
+ required_ruby_version: !ruby/object:Gem::Requirement
220
+ none: false
221
+ requirements:
222
+ - - ! '>='
223
+ - !ruby/object:Gem::Version
224
+ version: '0'
225
+ segments:
226
+ - 0
227
+ hash: 2769852841103375890
228
+ required_rubygems_version: !ruby/object:Gem::Requirement
229
+ none: false
230
+ requirements:
231
+ - - ! '>='
232
+ - !ruby/object:Gem::Version
233
+ version: '0'
234
+ requirements: []
235
+ rubyforge_project:
236
+ rubygems_version: 1.8.24
237
+ signing_key:
238
+ specification_version: 3
239
+ summary: A base class for error classes witin your application.
240
+ test_files: []