MrJaba-simple-exception-definition 0.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.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 [name of plugin creator]
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,59 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/clean'
6
+
7
+ include FileUtils
8
+
9
+ desc 'Default: run unit tests.'
10
+ task :default => :test
11
+
12
+ desc 'Test the simple_exception_definition plugin.'
13
+ Rake::TestTask.new(:test) do |t|
14
+ t.libs << 'lib'
15
+ t.pattern = 'test/**/*_test.rb'
16
+ t.verbose = true
17
+ end
18
+
19
+ desc 'Generate documentation for the simple_exception_definition plugin.'
20
+ Rake::RDocTask.new(:rdoc) do |rdoc|
21
+ rdoc.rdoc_dir = 'rdoc'
22
+ rdoc.title = 'SimpleExceptionDefinition'
23
+ rdoc.options << '--line-numbers' << '--inline-source'
24
+ rdoc.rdoc_files.include('README')
25
+ rdoc.rdoc_files.include('lib/**/*.rb')
26
+ end
27
+
28
+ NAME = "simple-exception-definition"
29
+ GEMVERSION = "0.1"
30
+
31
+ CLEAN.include "pkg"
32
+
33
+ spec = Gem::Specification.new do |s|
34
+ s.name = NAME
35
+ s.version = GEMVERSION
36
+ s.platform = Gem::Platform::RUBY
37
+ s.author = "Tom Crinson"
38
+ s.email = "the.jaba@gmail.com"
39
+ s.summary = "DRY up your exception definitions"
40
+ s.description = s.summary
41
+ s.require_path = "lib"
42
+ s.files = %w( MIT-LICENSE Rakefile ) + Dir["{lib}/**/*"]
43
+ end
44
+
45
+ Rake::GemPackageTask.new(spec) do |package|
46
+ package.gem_spec = spec
47
+ end
48
+
49
+ desc "Create a gemspec file"
50
+ task :make_spec do
51
+ File.open("#{NAME}.gemspec", "w") do |file|
52
+ file.puts spec.to_ruby
53
+ end
54
+ end
55
+
56
+ desc "Run :package and install the resulting .gem"
57
+ task :install => :package do
58
+ sh %{sudo gem install --local pkg/#{NAME}-#{GEMVERSION}.gem --no-rdoc --no-ri}
59
+ end
@@ -0,0 +1,25 @@
1
+ module SimpleExceptionDefinition
2
+
3
+ def define_exception( exception_class_name )
4
+ klass_name = Class.new(StandardError)
5
+ klass_name.class_eval do
6
+ attr_reader :object
7
+ def initialize( message=nil, object=nil )
8
+ @object = object
9
+ @message = message || "#{self.class.to_s} error"
10
+ end
11
+ def message
12
+ @message
13
+ end
14
+ end
15
+ Object.const_set( exception_class_name.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }, klass_name )
16
+ end
17
+
18
+ def define_exceptions( *args )
19
+ args.each { |arg| define_exception(arg) }
20
+ end
21
+
22
+ end
23
+
24
+
25
+ Object.extend( SimpleExceptionDefinition )
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: MrJaba-simple-exception-definition
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Tom Crinson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-18 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: DRY up your exception definitions
17
+ email: the.jaba@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - MIT-LICENSE
26
+ - Rakefile
27
+ - lib/simple_exception_definition.rb
28
+ has_rdoc: false
29
+ homepage:
30
+ post_install_message:
31
+ rdoc_options: []
32
+
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ version:
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ requirements: []
48
+
49
+ rubyforge_project:
50
+ rubygems_version: 1.2.0
51
+ signing_key:
52
+ specification_version: 2
53
+ summary: DRY up your exception definitions
54
+ test_files: []
55
+