sixarm_ruby_defining 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/README.md +97 -0
- data/Rakefile +8 -0
- data/VERSION +1 -0
- data/lib/sixarm_ruby_defining.rb +83 -0
- data/test/sixarm_ruby_defining_test.rb +75 -0
- data.tar.gz.sig +0 -0
- metadata +79 -0
- metadata.gz.sig +0 -0
data/.gemtest
ADDED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# SixArm.com » Ruby » <br> Class#defining and #redefining metaprogramming methods
|
2
|
+
|
3
|
+
* Docs: <http://sixarm.com/sixarm_ruby_defining/doc>
|
4
|
+
* Repo: <http://github.com/sixarm/sixarm_ruby_defining>
|
5
|
+
* Email: Joel Parker Henderson, <joel@sixarm.com>
|
6
|
+
|
7
|
+
|
8
|
+
## Introduction
|
9
|
+
|
10
|
+
Meta-programming method that you call when you are defining
|
11
|
+
a class method, to detect if your class may be accidentally
|
12
|
+
overriding an existing method.
|
13
|
+
|
14
|
+
For docs go to <http://sixarm.com/sixarm_ruby_defining/doc>
|
15
|
+
|
16
|
+
Want to help? We're happy to get pull requests.
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
## Quickstart
|
21
|
+
|
22
|
+
Install:
|
23
|
+
|
24
|
+
gem install sixarm_ruby_defining
|
25
|
+
|
26
|
+
Bundler:
|
27
|
+
|
28
|
+
gem "sixarm_ruby_defining", "=1.1.0"
|
29
|
+
|
30
|
+
Require:
|
31
|
+
|
32
|
+
require "sixarm_ruby_defining"
|
33
|
+
|
34
|
+
|
35
|
+
## Install with high security (optional)
|
36
|
+
|
37
|
+
To enable high security for all our gems:
|
38
|
+
|
39
|
+
wget http://sixarm.com/sixarm.pem
|
40
|
+
gem cert --add sixarm.pem
|
41
|
+
gem sources --add http://sixarm.com
|
42
|
+
|
43
|
+
To install with high security:
|
44
|
+
|
45
|
+
gem install sixarm_ruby_defining --test --trust-policy HighSecurity
|
46
|
+
|
47
|
+
|
48
|
+
## Example
|
49
|
+
|
50
|
+
class MyClass
|
51
|
+
|
52
|
+
# raise an error if 'foo' is already a method
|
53
|
+
defining 'foo'
|
54
|
+
|
55
|
+
# raise an error if 'to_s' is NOT already a method
|
56
|
+
redefining 'to_s'
|
57
|
+
|
58
|
+
# you can check many names at once
|
59
|
+
defining 'foo', 'goo', 'hoo',
|
60
|
+
redefining 'to_s', 'equal?', 'clone'
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
## Changes
|
66
|
+
|
67
|
+
* 2012-03-17 1.1.0 Upgrade for Ruby 1.9.3, minitest/spec, and improved docs.
|
68
|
+
* 2011-10-08 1.0.6 Updates for gem publishing
|
69
|
+
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
You may choose any of these open source licenses:
|
74
|
+
|
75
|
+
* Apache License
|
76
|
+
* BSD License
|
77
|
+
* CreativeCommons License, Non-commercial Share Alike
|
78
|
+
* GNU General Public License Version 2 (GPL 2)
|
79
|
+
* GNU Lesser General Public License (LGPL)
|
80
|
+
* MIT License
|
81
|
+
* Perl Artistic License
|
82
|
+
* Ruby License
|
83
|
+
|
84
|
+
The software is provided "as is", without warranty of any kind,
|
85
|
+
express or implied, including but not limited to the warranties of
|
86
|
+
merchantability, fitness for a particular purpose and noninfringement.
|
87
|
+
|
88
|
+
In no event shall the authors or copyright holders be liable for any
|
89
|
+
claim, damages or other liability, whether in an action of contract,
|
90
|
+
tort or otherwise, arising from, out of or in connection with the
|
91
|
+
software or the use or other dealings in the software.
|
92
|
+
|
93
|
+
This license is for the included software that is created by SixArm;
|
94
|
+
some of the included software may have its own licenses, copyrights,
|
95
|
+
authors, etc. and these do take precedence over the SixArm license.
|
96
|
+
|
97
|
+
Copyright (c) 2005-2013 Joel Parker Henderson
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.6
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
=begin rdoc
|
3
|
+
Please see README
|
4
|
+
=end
|
5
|
+
|
6
|
+
|
7
|
+
class Class
|
8
|
+
|
9
|
+
# To protect your code, call this just before you define a new method.
|
10
|
+
#
|
11
|
+
# ==Example
|
12
|
+
# class MyClass
|
13
|
+
# defining :foo
|
14
|
+
# def foo
|
15
|
+
# "hello world"
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# See #redefining
|
20
|
+
|
21
|
+
def defining(*method_names)
|
22
|
+
[*method_names].each{|m|
|
23
|
+
!method_defined?(m) ? defining_success(m) : defining_failure(m)
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
# Called when #defining sees that you are creating a new method.
|
29
|
+
#
|
30
|
+
# This method is blank; you can override it if you want to provide
|
31
|
+
# features like logging, coverage analysis, reporting, etc.
|
32
|
+
|
33
|
+
def defining_success(method_name)
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
# Called when #defining sees that you are creating a method that already exists.
|
38
|
+
#
|
39
|
+
# This method raises an error with a diagnostic message.
|
40
|
+
|
41
|
+
def defining_failure(method_name)
|
42
|
+
raise "Class#defining expects '#{method_name}' to be a new method, but it already exists: #{self}##{method_name}"
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
# To protect your code, call this just before you redefine an existing method.
|
47
|
+
#
|
48
|
+
# ==Example
|
49
|
+
# class MyClass
|
50
|
+
# redefining :to_s
|
51
|
+
# def to_s
|
52
|
+
# "hello world"
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# See #redefining
|
57
|
+
|
58
|
+
def redefining(*method_names)
|
59
|
+
[*method_names].each{|m|
|
60
|
+
method_defined?(m) ? redefining_success(m) : redefining_failure(m)
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
# Called when #redefining sees that you are overriding an existing method.
|
66
|
+
#
|
67
|
+
# This method is blank; you can override it if you want to provide
|
68
|
+
# features like logging, coverage analysis, reporting, etc.
|
69
|
+
|
70
|
+
def redefining_success(method_name)
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
# Called when #redefining sees that you are creating a method that doesn't exist.
|
75
|
+
#
|
76
|
+
# This method raises an error with a diagnostic message.
|
77
|
+
|
78
|
+
def redefining_failure(method_name)
|
79
|
+
raise "Class#redefining expects '#{method_name}' to be overriding an existing method, but it doesn't exist"
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
require 'sixarm_ruby_defining'
|
6
|
+
|
7
|
+
class Testing < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def test_defining_one_should_be_success
|
10
|
+
assert_nothing_raised do
|
11
|
+
eval "class C
|
12
|
+
defining 'nonexistant'
|
13
|
+
end"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_defining_many_should_be_success
|
18
|
+
assert_nothing_raised do
|
19
|
+
eval "class C
|
20
|
+
defining 'nonexistant', 'nonexistant2', 'nonexistant3'
|
21
|
+
end"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_defining_one_should_be_failure
|
26
|
+
assert_raise RuntimeError do
|
27
|
+
eval "class C
|
28
|
+
defining 'to_s'
|
29
|
+
end"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def test_defining_many_should_be_failure
|
35
|
+
assert_raise RuntimeError do
|
36
|
+
eval "class C
|
37
|
+
defining 'to_s', 'clone', 'equal?'
|
38
|
+
end"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_redefining_one_should_be_success
|
43
|
+
assert_nothing_raised do
|
44
|
+
eval "class C
|
45
|
+
redefining 'to_s'
|
46
|
+
end"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_redefining_many_should_be_success
|
51
|
+
assert_nothing_raised do
|
52
|
+
eval "class C
|
53
|
+
redefining 'to_s', 'clone', 'equal?'
|
54
|
+
end"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_redefining_one_should_be_failure
|
59
|
+
assert_raise RuntimeError do
|
60
|
+
eval "class C
|
61
|
+
redefining 'nonexistant'
|
62
|
+
end"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_redefining_many_should_be_failure
|
67
|
+
assert_raise RuntimeError do
|
68
|
+
eval "class C
|
69
|
+
redefining 'nonexistant1', 'nonexistant2', 'nonexistant3'
|
70
|
+
end"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sixarm_ruby_defining
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- SixArm
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain:
|
12
|
+
- !binary |-
|
13
|
+
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURCRENDQW0yZ0F3SUJB
|
14
|
+
Z0lKQUtQd0VFVFU1YkhvTUEwR0NTcUdTSWIzRFFFQkJRVUFNR0F4Q3pBSkJn
|
15
|
+
TlYKQkFZVEFsVlRNUk13RVFZRFZRUUlFd3BEWVd4cFptOXlibWxoTVJZd0ZB
|
16
|
+
WURWUVFIRXcxVFlXNGdSbkpoYm1OcApjMk52TVE4d0RRWURWUVFLRXdaVGFY
|
17
|
+
aEJjbTB4RXpBUkJnTlZCQU1UQ25OcGVHRnliUzVqYjIwd0hoY05NVEF4Ck1q
|
18
|
+
RXpNak15TnpFeldoY05NVE13T1RBNE1qTXlOekV6V2pCZ01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IrRXhS
|
34
|
+
d1dhZEd3YU5QVUE1NmQzOXF3YXZ3UCtpdSszSnBlb25OTVZ2YldYRjVuYUNY
|
35
|
+
L2RORkllUkVIekVSClpEUlFZTXFydTlURU1uYTZIRDl6cGNzdEY3dndUaEdv
|
36
|
+
dmxPUSszWTZwbFE0bk16aXBYY1o5VEhxczY1UElMMHEKZWFid3BDYkFvcG89
|
37
|
+
Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
|
38
|
+
date: 2012-03-19 00:00:00.000000000 Z
|
39
|
+
dependencies: []
|
40
|
+
description:
|
41
|
+
email: sixarm@sixarm.com
|
42
|
+
executables: []
|
43
|
+
extensions: []
|
44
|
+
extra_rdoc_files: []
|
45
|
+
files:
|
46
|
+
- .gemtest
|
47
|
+
- Rakefile
|
48
|
+
- README.md
|
49
|
+
- VERSION
|
50
|
+
- lib/sixarm_ruby_defining.rb
|
51
|
+
- test/sixarm_ruby_defining_test.rb
|
52
|
+
homepage: http://sixarm.com/
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.11
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: SixArm.com Ruby Class#defining and Class#redfining methods to detect if you're
|
76
|
+
creating a class method, or overriding
|
77
|
+
test_files:
|
78
|
+
- test/sixarm_ruby_defining_test.rb
|
79
|
+
has_rdoc: true
|
metadata.gz.sig
ADDED
Binary file
|