e2mmap 0.1.0

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,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: eb390d7392e6ddf2b47ce185b190eb667fa171d29c79717047a1ba633c4713fd
4
+ data.tar.gz: 92471415a2e9babb3320f0c93148ff591de7eb52216b96f370a8bbd3faf239dd
5
+ SHA512:
6
+ metadata.gz: 85f82596f8886a637922eee0740afba476036bb048ab331b7ba263fd0a6272f2a202303861051cdebe015a5af708890e7aa933b840c69d0520588d796c5b7cdc
7
+ data.tar.gz: 7b0f5637a0785da7255fdd42547889c3a2e9016a4e6107afc101f6f0c3031688dc42f5c83abbb445873f8c15c2bf76e8d6dc48fc3dd59ae464266d2a2118b816
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in e2mmap.gemspec
6
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ SUCH DAMAGE.
@@ -0,0 +1,85 @@
1
+ # Exception2MessageMapper
2
+
3
+ Helper module for easily defining exceptions with predefined messages.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'e2mmap'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install e2mmap
20
+
21
+ ## Usage
22
+
23
+ 1.
24
+
25
+ ```
26
+ class Foo
27
+ extend Exception2MessageMapper
28
+ def_e2message ExistingExceptionClass, "message..."
29
+ def_exception :NewExceptionClass, "message..."[, superclass]
30
+ ...
31
+ end
32
+ ```
33
+
34
+ 2.
35
+
36
+ ```
37
+ module Error
38
+ extend Exception2MessageMapper
39
+ def_e2message ExistingExceptionClass, "message..."
40
+ def_exception :NewExceptionClass, "message..."[, superclass]
41
+ ...
42
+ end
43
+
44
+ class Foo
45
+ include Error
46
+ ...
47
+ end
48
+
49
+ foo = Foo.new
50
+ foo.Fail ....
51
+ ```
52
+
53
+ 3.
54
+
55
+ ```
56
+ module Error
57
+ extend Exception2MessageMapper
58
+ def_e2message ExistingExceptionClass, "message..."
59
+ def_exception :NewExceptionClass, "message..."[, superclass]
60
+ ...
61
+ end
62
+
63
+ class Foo
64
+ extend Exception2MessageMapper
65
+ include Error
66
+ ...
67
+ end
68
+
69
+ Foo.Fail NewExceptionClass, arg...
70
+ Foo.Fail ExistingExceptionClass, arg...
71
+ ```
72
+
73
+ ## Development
74
+
75
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
76
+
77
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
78
+
79
+ ## Contributing
80
+
81
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/e2mmap.
82
+
83
+ ## License
84
+
85
+ The gem is available as open source under the terms of the [2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "e2mmap"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ begin
2
+ require_relative "lib/e2mmap/version"
3
+ rescue LoadError
4
+ # for Ruby core repository
5
+ require_relative "e2mmap/version"
6
+ end
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "e2mmap"
10
+ spec.version = Exception2MessageMapper::VERSION
11
+ spec.authors = ["Keiju ISHITSUKA"]
12
+ spec.email = ["keiju@ruby-lang.org"]
13
+
14
+ spec.summary = %q{Module for defining custom exceptions with specific messages.}
15
+ spec.description = %q{Module for defining custom exceptions with specific messages.}
16
+ spec.homepage = "https://github.com/ruby/e2mmap"
17
+ spec.license = "BSD-2-Clause"
18
+
19
+ spec.files = [".gitignore", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "bin/console", "bin/setup", "e2mmap.gemspec", "lib/e2mmap.rb", "lib/e2mmap/version.rb"]
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
@@ -0,0 +1,177 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ #--
4
+ # e2mmap.rb - for Ruby 1.1
5
+ # $Release Version: 2.0$
6
+ # $Revision: 1.10 $
7
+ # by Keiju ISHITSUKA
8
+ #
9
+ #++
10
+ #
11
+ # Helper module for easily defining exceptions with predefined messages.
12
+ #
13
+ # == Usage
14
+ #
15
+ # 1.
16
+ # class Foo
17
+ # extend Exception2MessageMapper
18
+ # def_e2message ExistingExceptionClass, "message..."
19
+ # def_exception :NewExceptionClass, "message..."[, superclass]
20
+ # ...
21
+ # end
22
+ #
23
+ # 2.
24
+ # module Error
25
+ # extend Exception2MessageMapper
26
+ # def_e2message ExistingExceptionClass, "message..."
27
+ # def_exception :NewExceptionClass, "message..."[, superclass]
28
+ # ...
29
+ # end
30
+ # class Foo
31
+ # include Error
32
+ # ...
33
+ # end
34
+ #
35
+ # foo = Foo.new
36
+ # foo.Fail ....
37
+ #
38
+ # 3.
39
+ # module Error
40
+ # extend Exception2MessageMapper
41
+ # def_e2message ExistingExceptionClass, "message..."
42
+ # def_exception :NewExceptionClass, "message..."[, superclass]
43
+ # ...
44
+ # end
45
+ # class Foo
46
+ # extend Exception2MessageMapper
47
+ # include Error
48
+ # ...
49
+ # end
50
+ #
51
+ # Foo.Fail NewExceptionClass, arg...
52
+ # Foo.Fail ExistingExceptionClass, arg...
53
+ #
54
+ #
55
+ module Exception2MessageMapper
56
+
57
+ E2MM = Exception2MessageMapper # :nodoc:
58
+
59
+ def E2MM.extend_object(cl)
60
+ super
61
+ cl.bind(self) unless cl < E2MM
62
+ end
63
+
64
+ def bind(cl)
65
+ self.module_eval "#{<<-"begin;"}\n#{<<-"end;"}", __FILE__, __LINE__+1
66
+ begin;
67
+ def Raise(err = nil, *rest)
68
+ Exception2MessageMapper.Raise(self.class, err, *rest)
69
+ end
70
+ alias Fail Raise
71
+
72
+ class << self
73
+ undef included
74
+ end
75
+ def self.included(mod)
76
+ mod.extend Exception2MessageMapper
77
+ end
78
+ end;
79
+ end
80
+
81
+ # Fail(err, *rest)
82
+ # err: exception
83
+ # rest: message arguments
84
+ #
85
+ def Raise(err = nil, *rest)
86
+ E2MM.Raise(self, err, *rest)
87
+ end
88
+ alias Fail Raise
89
+ alias fail Raise
90
+
91
+ # def_e2message(c, m)
92
+ # c: exception
93
+ # m: message_form
94
+ # define exception c with message m.
95
+ #
96
+ def def_e2message(c, m)
97
+ E2MM.def_e2message(self, c, m)
98
+ end
99
+
100
+ # def_exception(n, m, s)
101
+ # n: exception_name
102
+ # m: message_form
103
+ # s: superclass(default: StandardError)
104
+ # define exception named ``c'' with message m.
105
+ #
106
+ def def_exception(n, m, s = StandardError)
107
+ E2MM.def_exception(self, n, m, s)
108
+ end
109
+
110
+ #
111
+ # Private definitions.
112
+ #
113
+ # {[class, exp] => message, ...}
114
+ @MessageMap = {}
115
+
116
+ # E2MM.def_e2message(k, e, m)
117
+ # k: class to define exception under.
118
+ # e: exception
119
+ # m: message_form
120
+ # define exception c with message m.
121
+ #
122
+ def E2MM.def_e2message(k, c, m)
123
+ E2MM.instance_eval{@MessageMap[[k, c]] = m}
124
+ c
125
+ end
126
+
127
+ # E2MM.def_exception(k, n, m, s)
128
+ # k: class to define exception under.
129
+ # n: exception_name
130
+ # m: message_form
131
+ # s: superclass(default: StandardError)
132
+ # define exception named ``c'' with message m.
133
+ #
134
+ def E2MM.def_exception(k, n, m, s = StandardError)
135
+ e = Class.new(s)
136
+ E2MM.instance_eval{@MessageMap[[k, e]] = m}
137
+ k.module_eval {remove_const(n)} if k.const_defined?(n, false)
138
+ k.const_set(n, e)
139
+ end
140
+
141
+ # Fail(klass, err, *rest)
142
+ # klass: class to define exception under.
143
+ # err: exception
144
+ # rest: message arguments
145
+ #
146
+ def E2MM.Raise(klass = E2MM, err = nil, *rest)
147
+ if form = e2mm_message(klass, err)
148
+ b = $@.nil? ? caller(1) : $@
149
+ b.shift if b[0] =~ /^#{Regexp.quote(__FILE__)}:/
150
+ raise err, sprintf(form, *rest), b
151
+ else
152
+ E2MM.Fail E2MM, ErrNotRegisteredException, err.inspect
153
+ end
154
+ end
155
+ class << E2MM
156
+ alias Fail Raise
157
+ end
158
+
159
+ def E2MM.e2mm_message(klass, exp)
160
+ for c in klass.ancestors
161
+ if mes = @MessageMap[[c,exp]]
162
+ m = klass.instance_eval('"' + mes + '"')
163
+ return m
164
+ end
165
+ end
166
+ nil
167
+ end
168
+ class << self
169
+ alias message e2mm_message
170
+ end
171
+
172
+ E2MM.def_exception(E2MM,
173
+ :ErrNotRegisteredException,
174
+ "not registered exception(%s)")
175
+ end
176
+
177
+
@@ -0,0 +1,3 @@
1
+ module Exception2MessageMapper
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: e2mmap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Keiju ISHITSUKA
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Module for defining custom exceptions with specific messages.
42
+ email:
43
+ - keiju@ruby-lang.org
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - e2mmap.gemspec
56
+ - lib/e2mmap.rb
57
+ - lib/e2mmap/version.rb
58
+ homepage: https://github.com/ruby/e2mmap
59
+ licenses:
60
+ - BSD-2-Clause
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.7.6
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Module for defining custom exceptions with specific messages.
82
+ test_files: []