mabbre 0.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.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rubocop.yml +8 -0
- data/.ruby-version +1 -0
- data/.travis.yml +17 -0
- data/Gemfile +18 -0
- data/Guardfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +81 -0
- data/Rakefile +10 -0
- data/lib/mabbre/extension.rb +51 -0
- data/lib/mabbre/interpreter.rb +23 -0
- data/lib/mabbre/mixin.rb +48 -0
- data/lib/mabbre/version.rb +39 -0
- data/lib/mabbre.rb +2 -0
- data/mabbre.gemspec +21 -0
- data/spec/.rubocop.yml +4 -0
- data/spec/lib/mabbre/mixin_spec.rb +215 -0
- data/spec/lib/mabbre/version_spec.rb +5 -0
- data/spec/spec_helper.rb +21 -0
- data/tasks/console.rb +33 -0
- data/tasks/coverage.rb +9 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c5db2c5a298a84213898b57446f49f5f19f010b0
|
4
|
+
data.tar.gz: 1398a1fc8fef6a48ebfc1639674c3bf88369ec13
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 98edd86d51eed250ee24289b614e4b986aaae0f6b2c22d40eba048cca89849050e6b6802d7169dcbe82e259fe634cfdd57c75ee193604d8898d90f3c5a7afca1
|
7
|
+
data.tar.gz: 2e1e614d03708c085c1dc5b4de9765ce677c8217344ae2ad636f2ae1a23a49d030bcf38bba157e5b4770a103da2e9b3581f132b1fcacd82b3c0bc05c0656b6ec
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.5
|
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- ruby-head
|
4
|
+
- 2.1
|
5
|
+
- 2.0
|
6
|
+
- 1.9.3
|
7
|
+
- 1.9.2
|
8
|
+
- 1.8.7
|
9
|
+
- jruby-head
|
10
|
+
- jruby-1.7
|
11
|
+
- jruby-1.6
|
12
|
+
- rbx
|
13
|
+
bundler_args: "--without development"
|
14
|
+
addons:
|
15
|
+
code_climate:
|
16
|
+
repo_token:
|
17
|
+
secure: G3aVZeyCMZutQxsLu+hYHWgR/kqeLyn120obZwZ/17xc/VFx1y1F5f9Cqw/awj/f8+xl+UinOp69AM8w1JAEqD5I4N8L1nLJja+CSrWYUxSBOpGua6CtrEWB1VLyoxdXUNOL1oGQenKXZqQtbHRyUPuxebaP1K1XUHO3X5wnb6k=
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
gemspec
|
3
|
+
|
4
|
+
group :development do
|
5
|
+
gem "byebug", "~> 3.5.1"
|
6
|
+
gem "guard-rspec", "~> 4.3.1"
|
7
|
+
gem "guard-rubocop", "~> 1.2.0"
|
8
|
+
gem "libnotify", "~> 0.8.4"
|
9
|
+
gem "pry", "~> 0.10.1"
|
10
|
+
gem "rubocop", "~> 0.27.1"
|
11
|
+
end
|
12
|
+
|
13
|
+
group :development, :test do
|
14
|
+
gem "codeclimate-test-reporter", "~> 0.4.1"
|
15
|
+
gem "rake", "~> 10.3.2"
|
16
|
+
gem "rspec", "~> 3.1.0"
|
17
|
+
gem "simplecov", "~> 0.9.1"
|
18
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
guard :rspec, :cmd => "rspec -fd" do
|
2
|
+
watch(/^spec\/.+_spec\.rb$/)
|
3
|
+
watch(/^lib\/(.+)\.rb$/) {|m| "spec/lib/#{m[1]}_spec.rb" }
|
4
|
+
watch("spec/spec_helper.rb") { "spec" }
|
5
|
+
end
|
6
|
+
|
7
|
+
guard :rubocop do
|
8
|
+
watch(/^.+\.rb$/)
|
9
|
+
watch(/^(?:.+\/)?\.rubocop\.yml$/) {|m| File.dirname(m[0]) }
|
10
|
+
watch(/^(?:.+\/)?.+\.gemspec$/)
|
11
|
+
watch(/^(?:.+\/)?(?:Gem|Rake)file$/)
|
12
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Gabriel de Oliveira
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# MAbbre
|
2
|
+
|
3
|
+
[][gem]
|
4
|
+
[][travis]
|
5
|
+
[][codeclimate]
|
6
|
+
[][codeclimate]
|
7
|
+
[][gemnasium]
|
8
|
+
[][inch-ci]
|
9
|
+
|
10
|
+
[gem]: https://rubygems.org/gems/mabbre
|
11
|
+
[travis]: http://travis-ci.org/gdeoliveira/mabbre
|
12
|
+
[codeclimate]: https://codeclimate.com/github/gdeoliveira/mabbre
|
13
|
+
[gemnasium]: https://gemnasium.com/gdeoliveira/mabbre
|
14
|
+
[inch-ci]: http://inch-ci.org/github/gdeoliveira/mabbre
|
15
|
+
|
16
|
+
MAbbre allows a group of methods in a Class or a Module to be accessed using an abbreviated form. These methods can be defined anywhere within a hierarchy of inclusion and/or inheritance.
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem "mabbre"
|
24
|
+
```
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
$ bundle
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
$ gem install mtrack
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
Step 1: Define methods within an `allow_abbreviated` block in a Class or a Module:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
module M
|
40
|
+
extend MAbbre::Mixin
|
41
|
+
allow_abbreviated do
|
42
|
+
def very_long_method
|
43
|
+
"This method has a very long name."
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class C
|
49
|
+
include M
|
50
|
+
allow_abbreviated do
|
51
|
+
def another_long_method
|
52
|
+
"Another method with a long name."
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class D < C
|
58
|
+
allow_abbreviated do
|
59
|
+
def yet_another_long_method
|
60
|
+
"Yet another looong method name."
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
Step 2: Call these methods using a shortened name!
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
o = D.new
|
70
|
+
o.very #=> "This method has a very long name."
|
71
|
+
o.another #=> "Another method with a long name."
|
72
|
+
o.yet #=> "Yet another looong method name."
|
73
|
+
```
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
1. Fork it ( https://github.com/gdeoliveira/mabbre/fork )
|
78
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
79
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
80
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
81
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require "mabbre/interpreter"
|
2
|
+
|
3
|
+
module MAbbre
|
4
|
+
##
|
5
|
+
# This module is extended by MAbbre::Mixin and all custom extensions of MAbbre::Mixin. You should not extend this
|
6
|
+
# module directly, instead simply include MAbbre::Mixin into your custom extension:
|
7
|
+
#
|
8
|
+
# module MyExtension
|
9
|
+
# include MAbbre::Mixin
|
10
|
+
# # Define custom methods here.
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# module M
|
14
|
+
# extend MyExtension
|
15
|
+
# # You can use MAbbre's and MyExtension's methods here.
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# If you're overriding the +extended+ or +included+ methods in your custom extension always make sure to call +super+,
|
19
|
+
# so MAbbre can be properly initialized.
|
20
|
+
module Extension
|
21
|
+
private
|
22
|
+
|
23
|
+
##
|
24
|
+
# call-seq:
|
25
|
+
# extended(submodule) => submodule
|
26
|
+
#
|
27
|
+
# Includes MAbbre::Interpreter in +submodule+ (the Class or Module that extended MAbbre::Mixin).
|
28
|
+
#
|
29
|
+
# Returns passed +submodule+.
|
30
|
+
def extended(submodule)
|
31
|
+
super
|
32
|
+
submodule.instance_eval { include Interpreter }
|
33
|
+
submodule
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# call-seq:
|
38
|
+
# included(submodule) => submodule
|
39
|
+
#
|
40
|
+
# Initializes +submodule+ as a custom extension of MAbbre::Mixin. The new custom extension +submodule+ can then be
|
41
|
+
# extended by a Class or Module just like MAbbre::Mixin, or included further to generate other, more specific custom
|
42
|
+
# extensions.
|
43
|
+
#
|
44
|
+
# Returns passed +submodule+.
|
45
|
+
def included(submodule)
|
46
|
+
super
|
47
|
+
submodule.instance_eval { extend Extension }
|
48
|
+
submodule
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module MAbbre
|
2
|
+
##
|
3
|
+
# This module is added to the method lookup path and interprets abbreviations for tracked methods.
|
4
|
+
module Interpreter
|
5
|
+
private
|
6
|
+
|
7
|
+
##
|
8
|
+
# call-seq:
|
9
|
+
# method_missing(name, *args)
|
10
|
+
#
|
11
|
+
# If a suitable candidate for abbreviation +name+ is found it will be called using +args+. Otherwise it will let
|
12
|
+
# +super+ handle the missing method.
|
13
|
+
def method_missing(name, *args)
|
14
|
+
matched = nil
|
15
|
+
|
16
|
+
if self.class.tracked_methods(MAbbre).one? {|m| matched = m if m.to_s =~ /\A#{name}/ }
|
17
|
+
send(matched, *args)
|
18
|
+
else
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/mabbre/mixin.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require "mtrack"
|
2
|
+
require "mabbre/extension"
|
3
|
+
|
4
|
+
module MAbbre
|
5
|
+
##
|
6
|
+
# This module provides the #allow_abbreviated method to Classes or Modules that extend it.
|
7
|
+
module Mixin
|
8
|
+
include MTrack::Mixin
|
9
|
+
extend Extension
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
##
|
14
|
+
# call-seq:
|
15
|
+
# allow_abbreviated() => set
|
16
|
+
# allow_abbreviated() {|| ... } => set
|
17
|
+
#
|
18
|
+
# If a block is provided all the methods defined within the block will be accessible by using a shortened version of
|
19
|
+
# their name as long as no abiguities are found between them.
|
20
|
+
#
|
21
|
+
# Returns a set containing the methods that were defined within the block.
|
22
|
+
#
|
23
|
+
# class C
|
24
|
+
# extend MAbbre::Mixin
|
25
|
+
# allow_abbreviated do
|
26
|
+
# def long_method; end
|
27
|
+
# def longer_method; end
|
28
|
+
# def longest_method; end
|
29
|
+
# end
|
30
|
+
# end #=> #<Set: {:long_method, :longer_method, :longest_method}>
|
31
|
+
def allow_abbreviated(&b)
|
32
|
+
track_methods(MAbbre, &b)
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# call-seq:
|
37
|
+
# included(submodule) => submodule
|
38
|
+
#
|
39
|
+
# Adds the #allow_abbreviated method to +submodule+ by extending Mixin.
|
40
|
+
#
|
41
|
+
# Returns passed +submodule+.
|
42
|
+
def included(submodule)
|
43
|
+
super
|
44
|
+
submodule.instance_eval { extend Mixin }
|
45
|
+
submodule
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
##
|
2
|
+
# MAbbre allows a group of methods in a Class or a Module to be accessed using an abbreviated form. These methods can
|
3
|
+
# be defined anywhere within a hierarchy of inclusion and/or inheritance.
|
4
|
+
#
|
5
|
+
# module M
|
6
|
+
# extend MAbbre::Mixin
|
7
|
+
# allow_abbreviated do
|
8
|
+
# def very_long_method
|
9
|
+
# "This method has a very long name."
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# class C
|
15
|
+
# include M
|
16
|
+
# allow_abbreviated do
|
17
|
+
# def another_long_method
|
18
|
+
# "Another method with a long name."
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# class D < C
|
24
|
+
# allow_abbreviated do
|
25
|
+
# def yet_another_long_method
|
26
|
+
# "Yet another looong method name."
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# o = D.new
|
32
|
+
# o.very #=> "This method has a very long name."
|
33
|
+
# o.another #=> "Another method with a long name."
|
34
|
+
# o.yet #=> "Yet another looong method name."
|
35
|
+
module MAbbre
|
36
|
+
##
|
37
|
+
# Current version of MAbbre.
|
38
|
+
VERSION = "0.0.1"
|
39
|
+
end
|
data/lib/mabbre.rb
ADDED
data/mabbre.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "mabbre/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mabbre"
|
8
|
+
spec.version = MAbbre::VERSION
|
9
|
+
spec.authors = ["Gabriel de Oliveira"]
|
10
|
+
spec.email = ["deoliveira.gab@gmail.com"]
|
11
|
+
spec.summary = "Write a short summary. Required."
|
12
|
+
spec.description = "Write a longer description. Optional."
|
13
|
+
spec.homepage = "https://github.com/gdeoliveira/mabbre"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "mtrack", "~> 1.1.0"
|
21
|
+
end
|
data/spec/.rubocop.yml
ADDED
@@ -0,0 +1,215 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
METHOD_DEFINITION = proc { __method__ }
|
4
|
+
|
5
|
+
describe MAbbre::Mixin do
|
6
|
+
describe "#allow_abbreviated" do
|
7
|
+
it "is added after extending #{described_class}" do
|
8
|
+
mod = ::Module.new
|
9
|
+
expect(mod.private_methods.map(&:to_sym)).not_to include(:allow_abbreviated)
|
10
|
+
mod.module_eval { extend MAbbre::Mixin }
|
11
|
+
expect(mod.private_methods.map(&:to_sym)).to include(:allow_abbreviated)
|
12
|
+
end
|
13
|
+
|
14
|
+
context "block given" do
|
15
|
+
it "returns a set with the methods that can be abbreviated" do
|
16
|
+
mod = ::Module.new.module_eval do
|
17
|
+
extend MAbbre::Mixin
|
18
|
+
allow_abbreviated do
|
19
|
+
define_method :qwe, &METHOD_DEFINITION
|
20
|
+
define_method :asd, &METHOD_DEFINITION
|
21
|
+
define_method :zxc, &METHOD_DEFINITION
|
22
|
+
end
|
23
|
+
end
|
24
|
+
expect(mod).to be_a(Set)
|
25
|
+
expect(mod).to match_array([:qwe, :asd, :zxc])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "no block given" do
|
30
|
+
it "returns an empty set" do
|
31
|
+
mod = ::Module.new.module_eval do
|
32
|
+
extend MAbbre::Mixin
|
33
|
+
allow_abbreviated
|
34
|
+
end
|
35
|
+
expect(mod).to be_a(Set)
|
36
|
+
expect(mod).to be_empty
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "hierarchy" do
|
42
|
+
let(:base_extension) do
|
43
|
+
Module.new.tap do |m|
|
44
|
+
m.module_eval do
|
45
|
+
include MAbbre::Mixin
|
46
|
+
define_method :base_extension_meth, &METHOD_DEFINITION
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
let(:sub_extension) do
|
52
|
+
be = base_extension
|
53
|
+
Module.new.tap do |m|
|
54
|
+
m.module_eval do
|
55
|
+
include be
|
56
|
+
define_method :sub_extension_meth, &METHOD_DEFINITION
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
let(:base_module) do
|
62
|
+
se = sub_extension
|
63
|
+
Module.new.tap do |m|
|
64
|
+
m.module_eval do
|
65
|
+
extend se
|
66
|
+
define_method :meth_00_extra, &METHOD_DEFINITION
|
67
|
+
allow_abbreviated do
|
68
|
+
define_method :meth_01_extra, &METHOD_DEFINITION
|
69
|
+
define_method :meth_02_extra, &METHOD_DEFINITION
|
70
|
+
define_method :meth_03_extra, &METHOD_DEFINITION
|
71
|
+
end
|
72
|
+
define_method :meth_09_extra, &METHOD_DEFINITION
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
let(:sub_module) do
|
78
|
+
bm = base_module
|
79
|
+
Module.new.tap do |m|
|
80
|
+
m.module_eval do
|
81
|
+
include bm
|
82
|
+
define_method :meth_10_extra, &METHOD_DEFINITION
|
83
|
+
allow_abbreviated do
|
84
|
+
define_method :meth_11_extra, &METHOD_DEFINITION
|
85
|
+
define_method :meth_12_extra, &METHOD_DEFINITION
|
86
|
+
define_method :meth_13_extra, &METHOD_DEFINITION
|
87
|
+
end
|
88
|
+
define_method :meth_19_extra, &METHOD_DEFINITION
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
let(:super_class) do
|
94
|
+
sm = sub_module
|
95
|
+
Class.new.tap do |c|
|
96
|
+
c.class_eval do
|
97
|
+
include sm
|
98
|
+
define_method :meth_20_extra, &METHOD_DEFINITION
|
99
|
+
allow_abbreviated do
|
100
|
+
define_method :meth_21_extra, &METHOD_DEFINITION
|
101
|
+
define_method :meth_22_extra, &METHOD_DEFINITION
|
102
|
+
define_method :meth_23_extra, &METHOD_DEFINITION
|
103
|
+
end
|
104
|
+
define_method :meth_29_extra, &METHOD_DEFINITION
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
let(:sub_class) do
|
110
|
+
sc = super_class
|
111
|
+
Class.new(sc).tap do |c|
|
112
|
+
c.class_eval do
|
113
|
+
define_method :meth_30_extra, &METHOD_DEFINITION
|
114
|
+
allow_abbreviated do
|
115
|
+
define_method :meth_31_extra, &METHOD_DEFINITION
|
116
|
+
define_method :meth_32_extra, &METHOD_DEFINITION
|
117
|
+
define_method :meth_33_extra, &METHOD_DEFINITION
|
118
|
+
end
|
119
|
+
define_method :meth_39_extra, &METHOD_DEFINITION
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context "base module" do
|
125
|
+
subject { base_module }
|
126
|
+
|
127
|
+
it "has custom extensions as ancestors" do
|
128
|
+
expect(subject.singleton_methods.map(&:to_sym)).to include(:base_extension_meth, :sub_extension_meth)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "tracks methods that can be abbreviated" do
|
132
|
+
expect(subject.tracked_methods(MAbbre)).to match_array([:meth_01_extra, :meth_02_extra, :meth_03_extra])
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "sub module" do
|
137
|
+
subject { sub_module }
|
138
|
+
|
139
|
+
it "tracks methods that can be abbreviated" do
|
140
|
+
expect(subject.tracked_methods(MAbbre)).to match_array([:meth_01_extra, :meth_02_extra, :meth_03_extra,
|
141
|
+
:meth_11_extra, :meth_12_extra, :meth_13_extra])
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context "super class" do
|
146
|
+
subject { super_class }
|
147
|
+
|
148
|
+
it "tracks methods that can be abbreviated" do
|
149
|
+
expect(subject.tracked_methods(MAbbre)).to match_array([:meth_01_extra, :meth_02_extra, :meth_03_extra,
|
150
|
+
:meth_11_extra, :meth_12_extra, :meth_13_extra,
|
151
|
+
:meth_21_extra, :meth_22_extra, :meth_23_extra])
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "instance" do
|
155
|
+
subject { super_class.new }
|
156
|
+
|
157
|
+
it "avoids calling ambiguous methods" do
|
158
|
+
expect { subject.meth }.to raise_error(NoMethodError)
|
159
|
+
expect { subject.meth_0 }.to raise_error(NoMethodError)
|
160
|
+
expect { subject.meth_1 }.to raise_error(NoMethodError)
|
161
|
+
expect { subject.meth_2 }.to raise_error(NoMethodError)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "calls resolvable methods that can be abbreviated" do
|
165
|
+
expect(subject.meth_01).to be(:meth_01_extra)
|
166
|
+
expect(subject.meth_12).to be(:meth_12_extra)
|
167
|
+
expect(subject.meth_23).to be(:meth_23_extra)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "avoids calling resolvable methods that can't be abbreviated" do
|
171
|
+
expect { subject.meth_00 }.to raise_error(NoMethodError)
|
172
|
+
expect { subject.meth_10 }.to raise_error(NoMethodError)
|
173
|
+
expect { subject.meth_20 }.to raise_error(NoMethodError)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context "sub class" do
|
179
|
+
subject { sub_class }
|
180
|
+
|
181
|
+
it "tracks methods that can be abbreviated" do
|
182
|
+
expect(subject.tracked_methods(MAbbre)).to match_array([:meth_01_extra, :meth_02_extra, :meth_03_extra,
|
183
|
+
:meth_11_extra, :meth_12_extra, :meth_13_extra,
|
184
|
+
:meth_21_extra, :meth_22_extra, :meth_23_extra,
|
185
|
+
:meth_31_extra, :meth_32_extra, :meth_33_extra])
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "instance" do
|
189
|
+
subject { sub_class.new }
|
190
|
+
|
191
|
+
it "avoids calling ambiguous methods" do
|
192
|
+
expect { subject.meth }.to raise_error(NoMethodError)
|
193
|
+
expect { subject.meth_0 }.to raise_error(NoMethodError)
|
194
|
+
expect { subject.meth_1 }.to raise_error(NoMethodError)
|
195
|
+
expect { subject.meth_2 }.to raise_error(NoMethodError)
|
196
|
+
expect { subject.meth_3 }.to raise_error(NoMethodError)
|
197
|
+
end
|
198
|
+
|
199
|
+
it "calls resolvable methods that can be abbreviated" do
|
200
|
+
expect(subject.meth_02).to be(:meth_02_extra)
|
201
|
+
expect(subject.meth_13).to be(:meth_13_extra)
|
202
|
+
expect(subject.meth_21).to be(:meth_21_extra)
|
203
|
+
expect(subject.meth_32).to be(:meth_32_extra)
|
204
|
+
end
|
205
|
+
|
206
|
+
it "avoids calling resolvable methods that can't be abbreviated" do
|
207
|
+
expect { subject.meth_09 }.to raise_error(NoMethodError)
|
208
|
+
expect { subject.meth_19 }.to raise_error(NoMethodError)
|
209
|
+
expect { subject.meth_29 }.to raise_error(NoMethodError)
|
210
|
+
expect { subject.meth_39 }.to raise_error(NoMethodError)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
unless ENV["COVERAGE"].nil?
|
2
|
+
require "codeclimate-test-reporter"
|
3
|
+
SimpleCov.start do
|
4
|
+
formatter SimpleCov::Formatter::MultiFormatter[
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
CodeClimate::TestReporter::Formatter
|
7
|
+
]
|
8
|
+
add_filter "/spec/"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
13
|
+
require "mabbre"
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.color = true
|
17
|
+
config.order = :rand
|
18
|
+
config.expect_with :rspec do |c|
|
19
|
+
c.syntax = :expect
|
20
|
+
end
|
21
|
+
end
|
data/tasks/console.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
desc "Open a console with the #{Bundler::GemHelper.gemspec.name} gem loaded"
|
2
|
+
task :console do
|
3
|
+
require Bundler::GemHelper.gemspec.name
|
4
|
+
|
5
|
+
if RUBY_VERSION >= "2"
|
6
|
+
begin
|
7
|
+
require "byebug"
|
8
|
+
rescue LoadError # rubocop:disable Lint/HandleExceptions
|
9
|
+
end
|
10
|
+
else
|
11
|
+
begin
|
12
|
+
require "debugger"
|
13
|
+
rescue LoadError # rubocop:disable Lint/HandleExceptions
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
if RUBY_VERSION >= "1.9"
|
18
|
+
begin
|
19
|
+
require "pry"
|
20
|
+
rescue LoadError
|
21
|
+
require "irb"
|
22
|
+
end
|
23
|
+
else
|
24
|
+
require "irb"
|
25
|
+
end
|
26
|
+
|
27
|
+
if defined? Pry
|
28
|
+
Pry.start
|
29
|
+
else
|
30
|
+
ARGV.clear
|
31
|
+
IRB.start
|
32
|
+
end
|
33
|
+
end
|
data/tasks/coverage.rb
ADDED
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mabbre
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gabriel de Oliveira
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mtrack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.0
|
27
|
+
description: Write a longer description. Optional.
|
28
|
+
email:
|
29
|
+
- deoliveira.gab@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rubocop.yml"
|
36
|
+
- ".ruby-version"
|
37
|
+
- ".travis.yml"
|
38
|
+
- Gemfile
|
39
|
+
- Guardfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- lib/mabbre.rb
|
44
|
+
- lib/mabbre/extension.rb
|
45
|
+
- lib/mabbre/interpreter.rb
|
46
|
+
- lib/mabbre/mixin.rb
|
47
|
+
- lib/mabbre/version.rb
|
48
|
+
- mabbre.gemspec
|
49
|
+
- spec/.rubocop.yml
|
50
|
+
- spec/lib/mabbre/mixin_spec.rb
|
51
|
+
- spec/lib/mabbre/version_spec.rb
|
52
|
+
- spec/spec_helper.rb
|
53
|
+
- tasks/console.rb
|
54
|
+
- tasks/coverage.rb
|
55
|
+
homepage: https://github.com/gdeoliveira/mabbre
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.4.4
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Write a short summary. Required.
|
79
|
+
test_files:
|
80
|
+
- spec/.rubocop.yml
|
81
|
+
- spec/lib/mabbre/mixin_spec.rb
|
82
|
+
- spec/lib/mabbre/version_spec.rb
|
83
|
+
- spec/spec_helper.rb
|