abstract_type 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +37 -0
- data/.rvmrc +1 -0
- data/.travis.yml +19 -0
- data/Gemfile +59 -0
- data/Guardfile +18 -0
- data/LICENSE +21 -0
- data/README.md +99 -0
- data/Rakefile +9 -0
- data/TODO +0 -0
- data/abstract_type.gemspec +20 -0
- data/config/flay.yml +3 -0
- data/config/flog.yml +2 -0
- data/config/roodi.yml +18 -0
- data/config/site.reek +91 -0
- data/config/yardstick.yml +2 -0
- data/lib/abstract_type.rb +116 -0
- data/lib/abstract_type/version.rb +3 -0
- data/spec/rcov.opts +7 -0
- data/spec/shared/command_method_behavior.rb +7 -0
- data/spec/shared/each_method_behaviour.rb +15 -0
- data/spec/shared/hash_method_behavior.rb +17 -0
- data/spec/shared/idempotent_method_behavior.rb +7 -0
- data/spec/shared/invertible_method_behaviour.rb +9 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/config_alias.rb +3 -0
- data/spec/unit/abstract_type/class_methods/abstract_method_spec.rb +27 -0
- data/spec/unit/abstract_type/class_methods/abstract_singleton_method_spec.rb +21 -0
- data/spec/unit/abstract_type/class_methods/new_spec.rb +21 -0
- data/tasks/metrics/ci.rake +9 -0
- data/tasks/metrics/flay.rake +45 -0
- data/tasks/metrics/flog.rake +49 -0
- data/tasks/metrics/heckle.rake +208 -0
- data/tasks/metrics/metric_fu.rake +31 -0
- data/tasks/metrics/reek.rake +21 -0
- data/tasks/metrics/roodi.rake +19 -0
- data/tasks/metrics/yardstick.rake +25 -0
- data/tasks/spec.rake +60 -0
- data/tasks/yard.rake +11 -0
- metadata +138 -0
data/.gitignore
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## Rubinius
|
17
|
+
*.rbc
|
18
|
+
.rbx
|
19
|
+
|
20
|
+
## PROJECT::GENERAL
|
21
|
+
*.gem
|
22
|
+
coverage
|
23
|
+
profiling
|
24
|
+
turbulence
|
25
|
+
rdoc
|
26
|
+
pkg
|
27
|
+
tmp
|
28
|
+
doc
|
29
|
+
log
|
30
|
+
.yardoc
|
31
|
+
measurements
|
32
|
+
|
33
|
+
## BUNDLER
|
34
|
+
.bundle
|
35
|
+
Gemfile.lock
|
36
|
+
|
37
|
+
## PROJECT::SPECIFIC
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use @$(basename `pwd`) --create
|
data/.travis.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
language: ruby
|
2
|
+
before_install: gem install bundler
|
3
|
+
bundler_args: --without yard guard
|
4
|
+
script: "bundle exec rake spec"
|
5
|
+
rvm:
|
6
|
+
- 1.8.7
|
7
|
+
- 1.9.2
|
8
|
+
- 1.9.3
|
9
|
+
- jruby-18mode
|
10
|
+
- jruby-19mode
|
11
|
+
- rbx-18mode
|
12
|
+
- rbx-19mode
|
13
|
+
- ree
|
14
|
+
- ruby-head
|
15
|
+
- jruby-head
|
16
|
+
notifications:
|
17
|
+
email:
|
18
|
+
- dan.kubb@gmail.com
|
19
|
+
- mbj@seonic.net
|
data/Gemfile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
gemspec
|
6
|
+
|
7
|
+
group :yard do
|
8
|
+
gem 'yard', '~> 0.8.3'
|
9
|
+
gem 'redcarpet', '~> 2.2.2', :platforms => [ :mri, :rbx ]
|
10
|
+
end
|
11
|
+
|
12
|
+
group :guard do
|
13
|
+
gem 'guard', '~> 1.5.4'
|
14
|
+
gem 'guard-bundler', '~> 1.0.0'
|
15
|
+
gem 'guard-rspec', '~> 1.2.1'
|
16
|
+
end
|
17
|
+
|
18
|
+
group :benchmarks do
|
19
|
+
gem 'rbench', '~> 0.2.3'
|
20
|
+
end
|
21
|
+
|
22
|
+
platform :jruby do
|
23
|
+
group :jruby do
|
24
|
+
gem 'jruby-openssl', '~> 0.7.4'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
group :metrics do
|
29
|
+
gem 'flay', '~> 1.4.3'
|
30
|
+
gem 'flog', '~> 2.5.3'
|
31
|
+
gem 'reek', '~> 1.2.8', :github => 'dkubb/reek'
|
32
|
+
gem 'roodi', '~> 2.1.0'
|
33
|
+
gem 'yardstick', '~> 0.8.0'
|
34
|
+
|
35
|
+
platforms :ruby_18, :ruby_19 do
|
36
|
+
# this indirectly depends on ffi which does not build on ruby-head
|
37
|
+
gem 'yard-spellcheck', '~> 0.1.5'
|
38
|
+
end
|
39
|
+
|
40
|
+
platforms :mri_18 do
|
41
|
+
gem 'arrayfields', '~> 4.7.4' # for metric_fu
|
42
|
+
gem 'fattr', '~> 2.2.0' # for metric_fu
|
43
|
+
gem 'heckle', '~> 1.4.3'
|
44
|
+
gem 'json', '~> 1.7.3' # for metric_fu rake task
|
45
|
+
gem 'map', '~> 6.2.0' # for metric_fu
|
46
|
+
gem 'metric_fu', '~> 2.1.1'
|
47
|
+
gem 'mspec', '~> 1.5.17'
|
48
|
+
gem 'rcov', '~> 1.0.0'
|
49
|
+
gem 'ruby2ruby', '= 1.2.2' # for heckle
|
50
|
+
end
|
51
|
+
|
52
|
+
platforms :ruby_19 do
|
53
|
+
gem 'simplecov', '~> 0.7.1'
|
54
|
+
end
|
55
|
+
|
56
|
+
platforms :rbx do
|
57
|
+
gem 'pelusa', '~> 0.2.1'
|
58
|
+
end
|
59
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
guard :bundler do
|
4
|
+
watch('Gemfile')
|
5
|
+
end
|
6
|
+
|
7
|
+
guard :rspec do
|
8
|
+
# run all specs if the spec_helper or supporting files files are modified
|
9
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
10
|
+
watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec' }
|
11
|
+
|
12
|
+
# run unit specs if associated lib code is modified
|
13
|
+
watch(%r{\Alib/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}"] }
|
14
|
+
watch("lib/#{File.basename(File.expand_path('../', __FILE__))}.rb") { 'spec' }
|
15
|
+
|
16
|
+
# run a spec if it is modified
|
17
|
+
watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
|
18
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2009-2012 Dan Kubb
|
2
|
+
Copyright (c) 2012 Markus Schirp
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
abstract_type
|
2
|
+
==============
|
3
|
+
|
4
|
+
[![Build Status](https://secure.travis-ci.org/dkubb/abstract_type.png?branch=master)](http://travis-ci.org/dkubb/abstract_type)
|
5
|
+
[![Dependency Status](https://gemnasium.com/dkubb/abstract_type.png)](https://gemnasium.com/dkubb/abstract_type)
|
6
|
+
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/dkubb/abstract_type)
|
7
|
+
|
8
|
+
This is a small standalone gem featuring a module ripped out from [veritas](https://github.com/dkubb/veritas).
|
9
|
+
It allows to declare abstract_type classes and modules in an unobstrusive way.
|
10
|
+
|
11
|
+
Installation
|
12
|
+
------------
|
13
|
+
|
14
|
+
With Rubygems:
|
15
|
+
|
16
|
+
```bash
|
17
|
+
$ gem install abstract_type
|
18
|
+
$ irb -rubygems
|
19
|
+
>> require 'abstract_type'
|
20
|
+
=> true
|
21
|
+
```
|
22
|
+
|
23
|
+
With git and local working copy:
|
24
|
+
|
25
|
+
```bash
|
26
|
+
$ git clone git://github.com/dkubb/abstract_type.git
|
27
|
+
$ cd abstract_type
|
28
|
+
$ rake install
|
29
|
+
$ irb -rubygems
|
30
|
+
>> require 'abstract_type'
|
31
|
+
=> true
|
32
|
+
```
|
33
|
+
|
34
|
+
Examples
|
35
|
+
--------
|
36
|
+
|
37
|
+
``` ruby
|
38
|
+
class Foo
|
39
|
+
include AbstractType
|
40
|
+
|
41
|
+
# Declare abstract instance method
|
42
|
+
abstract :bar
|
43
|
+
|
44
|
+
# Declare abstract singleton method
|
45
|
+
abstract_singleton_method :singleton_method
|
46
|
+
end
|
47
|
+
|
48
|
+
Foo.new # raises NotImplementedError: Foo is an abstract type
|
49
|
+
Foo.singleton_method # raises NotImplementedError: Foo.bar is not implemented
|
50
|
+
|
51
|
+
# Subclassing to allow instanciation
|
52
|
+
class Baz < Foo; end
|
53
|
+
|
54
|
+
object = Baz.new
|
55
|
+
object.bar # raises NotImplementedError: Baz#bar is not implemented
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
Credits
|
60
|
+
-------
|
61
|
+
|
62
|
+
* Dan Kubb ([dkubb](https://github.com/dkubb))
|
63
|
+
* Markus Schirp ([dkubb](https://github.com/mbj))
|
64
|
+
|
65
|
+
Contributing
|
66
|
+
-------------
|
67
|
+
|
68
|
+
* If you want your code merged into the mainline, please discuss the proposed changes with me before doing any work on it. This library is still in early development, and the direction it is going may not always be clear. Some features may not be appropriate yet, may need to be deferred until later when the foundation for them is laid, or may be more applicable in a plugin.
|
69
|
+
* Fork the project.
|
70
|
+
* Make your feature addition or bug fix.
|
71
|
+
* Follow this [style guide](https://github.com/dkubb/styleguide).
|
72
|
+
* Add specs for it. This is important so I don't break it in a future version unintentionally. Tests must cover all branches within the code, and code must be fully covered.
|
73
|
+
* Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
74
|
+
* Run "rake ci". This must pass and not show any regressions in the metrics for the code to be merged.
|
75
|
+
* Send me a pull request. Bonus points for topic branc
|
76
|
+
|
77
|
+
License
|
78
|
+
-------
|
79
|
+
|
80
|
+
Copyright (c) 2001-2012 Dan Kubb
|
81
|
+
|
82
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
83
|
+
a copy of this software and associated documentation files (the
|
84
|
+
"Software"), to deal in the Software without restriction, including
|
85
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
86
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
87
|
+
permit persons to whom the Software is furnished to do so, subject to
|
88
|
+
the following conditions:
|
89
|
+
|
90
|
+
The above copyright notice and this permission notice shall be
|
91
|
+
included in all copies or substantial portions of the Software.
|
92
|
+
|
93
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
94
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
95
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
96
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
97
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
98
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
99
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/TODO
ADDED
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../lib/abstract_type/version', __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'abstract_type'
|
7
|
+
gem.version = AbstractType::VERSION.dup
|
8
|
+
gem.authors = [ 'Dan Kubb' ]
|
9
|
+
gem.email = %w[ dan.kubb@gmail.com ]
|
10
|
+
gem.description = 'Module to declare abstract classes and methods'
|
11
|
+
gem.summary = gem.description
|
12
|
+
gem.homepage = 'https://github.com/dkubb/abstract_type'
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.test_files = `git ls-files -- {spec}/*`.split($/)
|
16
|
+
gem.extra_rdoc_files = %w[LICENSE README.md TODO]
|
17
|
+
|
18
|
+
gem.add_development_dependency('rake', '~> 10.0.2')
|
19
|
+
gem.add_development_dependency('rspec', '~> 1.3.2')
|
20
|
+
end
|
data/config/flay.yml
ADDED
data/config/flog.yml
ADDED
data/config/roodi.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
AbcMetricMethodCheck: { score: 10.3 }
|
3
|
+
AssignmentInConditionalCheck: { }
|
4
|
+
CaseMissingElseCheck: { }
|
5
|
+
ClassLineCountCheck: { line_count: 293 }
|
6
|
+
ClassNameCheck: { pattern: !ruby/regexp '/\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/' }
|
7
|
+
ClassVariableCheck: { }
|
8
|
+
CyclomaticComplexityBlockCheck: { complexity: 2 }
|
9
|
+
CyclomaticComplexityMethodCheck: { complexity: 4 }
|
10
|
+
EmptyRescueBodyCheck: { }
|
11
|
+
ForLoopCheck: { }
|
12
|
+
# TODO: decrease line_count to 5 to 10
|
13
|
+
MethodLineCountCheck: { line_count: 14 }
|
14
|
+
MethodNameCheck: { pattern: !ruby/regexp '/\A(?:[a-z\d](?:_?[a-z\d])+[?!=]?|\[\]=?|==|<=>|[+*&|-])\z/' }
|
15
|
+
ModuleLineCountCheck: { line_count: 295 }
|
16
|
+
ModuleNameCheck: { pattern: !ruby/regexp '/\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/' }
|
17
|
+
# TODO: decrease parameter_count to 2 or less
|
18
|
+
ParameterNumberCheck: { parameter_count: 3 }
|
data/config/site.reek
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
---
|
2
|
+
UncommunicativeParameterName:
|
3
|
+
accept: []
|
4
|
+
exclude: []
|
5
|
+
enabled: true
|
6
|
+
reject:
|
7
|
+
- !ruby/regexp /^.$/
|
8
|
+
- !ruby/regexp /[0-9]$/
|
9
|
+
- !ruby/regexp /[A-Z]/
|
10
|
+
LargeClass:
|
11
|
+
max_methods: 10
|
12
|
+
exclude: []
|
13
|
+
enabled: true
|
14
|
+
max_instance_variables: 2
|
15
|
+
UncommunicativeMethodName:
|
16
|
+
accept: []
|
17
|
+
exclude: []
|
18
|
+
enabled: true
|
19
|
+
reject:
|
20
|
+
- !ruby/regexp /^[a-z]$/
|
21
|
+
- !ruby/regexp /[0-9]$/
|
22
|
+
- !ruby/regexp /[A-Z]/
|
23
|
+
LongParameterList:
|
24
|
+
max_params: 2 # TODO: decrease max_params to 2
|
25
|
+
exclude: []
|
26
|
+
enabled: true
|
27
|
+
overrides: {}
|
28
|
+
FeatureEnvy:
|
29
|
+
exclude: []
|
30
|
+
enabled: true
|
31
|
+
ClassVariable:
|
32
|
+
exclude: []
|
33
|
+
enabled: true
|
34
|
+
BooleanParameter:
|
35
|
+
exclude: []
|
36
|
+
enabled: true
|
37
|
+
IrresponsibleModule:
|
38
|
+
exclude: []
|
39
|
+
enabled: true
|
40
|
+
UncommunicativeModuleName:
|
41
|
+
accept: []
|
42
|
+
exclude: []
|
43
|
+
enabled: true
|
44
|
+
reject:
|
45
|
+
- !ruby/regexp /^.$/
|
46
|
+
- !ruby/regexp /[0-9]$/
|
47
|
+
NestedIterators:
|
48
|
+
ignore_iterators: []
|
49
|
+
exclude: []
|
50
|
+
enabled: true
|
51
|
+
max_allowed_nesting: 1
|
52
|
+
LongMethod:
|
53
|
+
max_statements: 7 # TODO: decrease max_statements to 5 or less
|
54
|
+
exclude: []
|
55
|
+
enabled: true
|
56
|
+
Duplication:
|
57
|
+
allow_calls: []
|
58
|
+
exclude: []
|
59
|
+
enabled: true
|
60
|
+
max_calls: 1
|
61
|
+
UtilityFunction:
|
62
|
+
max_helper_calls: 1
|
63
|
+
exclude: []
|
64
|
+
enabled: true
|
65
|
+
Attribute:
|
66
|
+
exclude: []
|
67
|
+
enabled: false
|
68
|
+
UncommunicativeVariableName:
|
69
|
+
accept: []
|
70
|
+
exclude: []
|
71
|
+
enabled: true
|
72
|
+
reject:
|
73
|
+
- !ruby/regexp /^.$/
|
74
|
+
- !ruby/regexp /[0-9]$/
|
75
|
+
- !ruby/regexp /[A-Z]/
|
76
|
+
SimulatedPolymorphism:
|
77
|
+
exclude: []
|
78
|
+
enabled: true
|
79
|
+
max_ifs: 1
|
80
|
+
DataClump:
|
81
|
+
exclude: []
|
82
|
+
enabled: true
|
83
|
+
max_copies: 1
|
84
|
+
min_clump_size: 3
|
85
|
+
ControlCouple:
|
86
|
+
exclude: []
|
87
|
+
enabled: true
|
88
|
+
LongYieldList:
|
89
|
+
max_params: 1
|
90
|
+
exclude: []
|
91
|
+
enabled: true
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Module to allow class and methods to be abstract
|
4
|
+
module AbstractType
|
5
|
+
|
6
|
+
# Hook called when module is included
|
7
|
+
#
|
8
|
+
# @param [Module] descendant
|
9
|
+
# the module or class including AbstractType
|
10
|
+
#
|
11
|
+
# @return [self]
|
12
|
+
#
|
13
|
+
# @api private
|
14
|
+
def self.included(descendant)
|
15
|
+
super
|
16
|
+
descendant.extend(ClassMethods)
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
|
22
|
+
# Instantiate a new object
|
23
|
+
#
|
24
|
+
# Ensures that the instance cannot be of the abstract type
|
25
|
+
# and must be a descendant.
|
26
|
+
#
|
27
|
+
# @example
|
28
|
+
# object = AbstractType.new
|
29
|
+
#
|
30
|
+
# @return [Object]
|
31
|
+
#
|
32
|
+
# @api public
|
33
|
+
def new(*)
|
34
|
+
if superclass.equal?(Object)
|
35
|
+
raise NotImplementedError, "#{self} is an abstract type"
|
36
|
+
else
|
37
|
+
super
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Create abstract instance methods
|
42
|
+
#
|
43
|
+
# @example
|
44
|
+
# class Foo
|
45
|
+
# include Abstract
|
46
|
+
#
|
47
|
+
# # Create an abstract instance method
|
48
|
+
# abstract_method :some_method
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# @param [Array<#to_s>] names
|
52
|
+
#
|
53
|
+
# @return [self]
|
54
|
+
#
|
55
|
+
# @api public
|
56
|
+
def abstract_method(*names)
|
57
|
+
names.each { |name| create_abstract_instance_method(name) }
|
58
|
+
self
|
59
|
+
end
|
60
|
+
|
61
|
+
# Create abstract singleton methods
|
62
|
+
#
|
63
|
+
# @example
|
64
|
+
# class Foo
|
65
|
+
# include Abstract
|
66
|
+
#
|
67
|
+
# # Create an abstract instance method
|
68
|
+
# abstract_singleton_method :some_method
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# @param [Array<#to_s>] names
|
72
|
+
#
|
73
|
+
# @return [self]
|
74
|
+
#
|
75
|
+
# @api private
|
76
|
+
def abstract_singleton_method(*names)
|
77
|
+
names.each { |name| create_abstract_singleton_method(name) }
|
78
|
+
self
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
# Create abstract singleton method
|
84
|
+
#
|
85
|
+
# @param [#to_s] name
|
86
|
+
# the name of the method to create
|
87
|
+
#
|
88
|
+
# @return [undefined]
|
89
|
+
#
|
90
|
+
# @api private
|
91
|
+
def create_abstract_singleton_method(name)
|
92
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
93
|
+
def self.#{name}(*) # def self.name(*)
|
94
|
+
raise NotImplementedError, "\#{name}.\#{__method__} is not implemented" # raise NotImplementedError, 'MyClass#name is not implemented'
|
95
|
+
end # end
|
96
|
+
RUBY
|
97
|
+
end
|
98
|
+
|
99
|
+
# Create abstract instance method
|
100
|
+
#
|
101
|
+
# @param [#to_s] name
|
102
|
+
# the name of the method to create
|
103
|
+
#
|
104
|
+
# @return [undefined]
|
105
|
+
#
|
106
|
+
# @api private
|
107
|
+
def create_abstract_instance_method(name)
|
108
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
109
|
+
def #{name}(*) # def name(*)
|
110
|
+
raise NotImplementedError, "\#{self.class.name}#\#{__method__} is not implemented" # raise NotImplementedError, 'MyClass.name is not implemented'
|
111
|
+
end # end
|
112
|
+
RUBY
|
113
|
+
end
|
114
|
+
|
115
|
+
end # module ClassMethods
|
116
|
+
end # module Abstract
|