frubby 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +20 -0
- data/README.md +52 -0
- data/Rakefile +8 -0
- data/frubby.gemspec +19 -0
- data/lib/frubby.rb +10 -0
- data/lib/frubby/const_missing.rb +12 -0
- data/lib/frubby/method_missing.rb +24 -0
- data/lib/frubby/respond_to_missing.rb +23 -0
- data/test.rb +29 -0
- data/test/test.rb +24 -0
- data/test/test_const_missing.rb +30 -0
- data/test/test_method_missing.rb +42 -0
- data/test/test_respond_to_missing.rb +42 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8e1959be0287a4d7aa58750c95f9d7c47950276a
|
4
|
+
data.tar.gz: ba4d2fda00d9448fd3e0f391702f9ecc80dc5857
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 94912e4b4295e745a14ce8ed0da8e9181e036c8be84c3d7e9573b71e2f17581def9f66f4bc933691798da78a046d5ce23dee9c17d16bc0ced7f6604a1485dddb
|
7
|
+
data.tar.gz: 57964fd29671c732200135e0d0cea4602725660b60f166f678989ca24444d038ac1f3ef0949fdd5c7ab5d8ad7c9b55ed9afc2fc17d7d4c7f22cd0cbbf618f29e
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# frubby
|
2
|
+
Bring fuzzy_match directly into ruby.
|
3
|
+
|
4
|
+
### Install
|
5
|
+
|
6
|
+
```
|
7
|
+
gem install frubby
|
8
|
+
```
|
9
|
+
|
10
|
+
### Example
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
require 'frubby'
|
14
|
+
|
15
|
+
class FancyTestClass
|
16
|
+
def initialize
|
17
|
+
@count = 0
|
18
|
+
end
|
19
|
+
|
20
|
+
def inc
|
21
|
+
@count += 1
|
22
|
+
end
|
23
|
+
|
24
|
+
def dec
|
25
|
+
@count -= 1
|
26
|
+
end
|
27
|
+
|
28
|
+
def inc_five
|
29
|
+
@count +=5
|
30
|
+
end
|
31
|
+
|
32
|
+
def count
|
33
|
+
@count
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
fr = FncyTstClas.new
|
38
|
+
fr.incc
|
39
|
+
fr.in
|
40
|
+
fr.in_fv
|
41
|
+
piuts fr.cunt # => 7
|
42
|
+
```
|
43
|
+
|
44
|
+
### Licence
|
45
|
+
|
46
|
+
Copyright (c) 2015 Michał Kalbarczyk
|
47
|
+
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
49
|
+
|
50
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
51
|
+
|
52
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/frubby.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'frubby'
|
3
|
+
s.version = '0.1'
|
4
|
+
s.license = 'MIT'
|
5
|
+
s.summary = 'Add color methods to String class'
|
6
|
+
s.description = 'Ruby String class extension. Adds methods to set text color, background color and, text effects on ruby console and command line output, using ANSI escape sequences.'
|
7
|
+
s.authors = ['Michał Kalbarczyk']
|
8
|
+
s.email = 'fazibear@gmail.com'
|
9
|
+
s.homepage = 'http://github.com/fazibear/frubby'
|
10
|
+
|
11
|
+
s.date = Time.now.strftime("%Y-%m-%d")
|
12
|
+
|
13
|
+
s.add_dependency 'fuzzy_match'
|
14
|
+
|
15
|
+
s.add_development_dependency 'rake'
|
16
|
+
s.add_development_dependency 'minitest'
|
17
|
+
|
18
|
+
s.files = Dir['**/*']
|
19
|
+
end
|
data/lib/frubby.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'fuzzy_match'
|
3
|
+
|
4
|
+
require 'frubby/method_missing'
|
5
|
+
require 'frubby/respond_to_missing'
|
6
|
+
require 'frubby/const_missing'
|
7
|
+
|
8
|
+
include Frubby::MethodMissing
|
9
|
+
include Frubby::RespondToMissing
|
10
|
+
Object.extend Frubby::ConstMissing
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Frubby
|
2
|
+
module ConstMissing
|
3
|
+
def const_missing(const)
|
4
|
+
_constants = (Object.constants + constants).flatten
|
5
|
+
_constant = FuzzyMatch.new(_constants).find(const)
|
6
|
+
|
7
|
+
puts "#{const} => #{_constant}" if $DEBUG
|
8
|
+
|
9
|
+
_constant ? const_get(_constant) : raise('const_missing')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Frubby
|
2
|
+
module MethodMissing
|
3
|
+
|
4
|
+
EXCLUDED_METHODS = %i[
|
5
|
+
to_ary
|
6
|
+
to_io
|
7
|
+
to_hash
|
8
|
+
to_str
|
9
|
+
]
|
10
|
+
|
11
|
+
KERNEL_METHODS = Kernel.methods.delete_if {|m| m.match /^[A-Z]/}
|
12
|
+
|
13
|
+
def method_missing(method_sym, *args, &block)
|
14
|
+
return if EXCLUDED_METHODS.include? method_sym
|
15
|
+
|
16
|
+
_methods = (KERNEL_METHODS + methods).flatten
|
17
|
+
_method = FuzzyMatch.new(_methods).find(method_sym.to_s)
|
18
|
+
|
19
|
+
puts "#{method_sym.to_s} -> #{_method.to_s}" if $DEBUG
|
20
|
+
|
21
|
+
_method.is_a?(Symbol) ? send(_method.to_s, *args, &block) : raise('method_missing')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Frubby
|
2
|
+
module RespondToMissing
|
3
|
+
|
4
|
+
EXCLUDED_RESPOND_TOS = %i[
|
5
|
+
begin
|
6
|
+
end
|
7
|
+
path
|
8
|
+
]
|
9
|
+
|
10
|
+
KERNEL_METHODS = Kernel.methods.delete_if {|m| m.match /^[A-Z]/}
|
11
|
+
|
12
|
+
def respond_to_missing?(method_name, include_private = false)
|
13
|
+
return false if EXCLUDED_RESPOND_TOS.include? method_name.to_sym
|
14
|
+
|
15
|
+
_methods = (KERNEL_METHODS + methods).flatten
|
16
|
+
_method = FuzzyMatch.new(_methods).find(method_name.to_sym)
|
17
|
+
|
18
|
+
puts "#{method_name} ~> #{_method}" if $DEBUG
|
19
|
+
|
20
|
+
_method.is_a?(Symbol)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/test.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'frubby'
|
2
|
+
|
3
|
+
class FancyTestClass
|
4
|
+
def initialize
|
5
|
+
@count = 0
|
6
|
+
end
|
7
|
+
|
8
|
+
def inc
|
9
|
+
@count += 1
|
10
|
+
end
|
11
|
+
|
12
|
+
def dec
|
13
|
+
@count -= 1
|
14
|
+
end
|
15
|
+
|
16
|
+
def inc_five
|
17
|
+
@count +=5
|
18
|
+
end
|
19
|
+
|
20
|
+
def count
|
21
|
+
@count
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
fr = FncyTstClas.new
|
26
|
+
fr.incc
|
27
|
+
fr.in
|
28
|
+
fr.in_fv
|
29
|
+
piuts fr.cunt # => 7
|
data/test/test.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require_relative '../lib/frubby'
|
3
|
+
|
4
|
+
class Test < Minitest::Test
|
5
|
+
def test_assert_method_missing
|
6
|
+
assert_eqal true, true
|
7
|
+
asert_eqal true, true
|
8
|
+
assrt_eqaal true, true
|
9
|
+
asset_eqal true, true
|
10
|
+
assser_etue true, true
|
11
|
+
assrt_false false, false
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_puts_method_missing
|
15
|
+
assert_equal true, respond_to?(:pts)
|
16
|
+
assert_equal true, respond_to?(:pus)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_integer_constant_missing
|
20
|
+
assert_equal Integer, Integr
|
21
|
+
assert_equal Integer, Inteer
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require_relative '../lib/frubby'
|
3
|
+
|
4
|
+
class ConstMissingTest < Minitest::Test
|
5
|
+
CONST_TEST = 'test'
|
6
|
+
|
7
|
+
class SampleClass
|
8
|
+
end
|
9
|
+
|
10
|
+
module SampleModule
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_missing_constant
|
14
|
+
assert_equal CONST_TEST, CONST_TET
|
15
|
+
assert_equal CONST_TEST, CONST_TST
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_missing_class_name
|
19
|
+
assert_equal SampleClass, SmpleCalss
|
20
|
+
assert_equal SampleClass, SapleCass
|
21
|
+
assert_equal SampleClass, SapleCalas
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_missing_module_name
|
25
|
+
assert_equal SampleModule, SmpleModule
|
26
|
+
assert_equal SampleModule, SapleMdule
|
27
|
+
assert_equal SampleModule, SapleMdle
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require_relative '../lib/frubby'
|
3
|
+
|
4
|
+
class MethodMissingTest < Minitest::Test
|
5
|
+
def sample_method
|
6
|
+
'test'
|
7
|
+
end
|
8
|
+
|
9
|
+
def sample_method_with_argument(arg)
|
10
|
+
"test #{arg}"
|
11
|
+
end
|
12
|
+
|
13
|
+
module SampleModule
|
14
|
+
def self.sample_method
|
15
|
+
'test'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_missing_method_name
|
20
|
+
assert_equal sample_method, smple_method
|
21
|
+
assert_equal sample_method, sample_mthod
|
22
|
+
assert_equal sample_method, sampe_method
|
23
|
+
assert_equal sample_method, sampe_mothod
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_missing_method_name_with_argument
|
27
|
+
assert_equal sample_method_with_argument('test'), smple_method_with_argmtn('test')
|
28
|
+
assert_equal sample_method_with_argument('test'), smple_meod_with_argmtn('test')
|
29
|
+
assert_equal sample_method_with_argument('test'), smple_method_with_argmtn('test')
|
30
|
+
assert_equal sample_method_with_argument('test'), smple_methd_wth_argmtn('test')
|
31
|
+
assert_equal sample_method_with_argument('test'), smple_method_with_agmtn('test')
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_missing_module_self_method_name
|
35
|
+
assert_equal SampleModule::sample_method, SampleModule::smple_method
|
36
|
+
assert_equal SampleModule::sample_method, SampleModule::smple_metod
|
37
|
+
assert_equal SampleModule::sample_method, SampleModule::smple_method
|
38
|
+
assert_equal SampleModule::sample_method, SampleModule::smple_ethod
|
39
|
+
assert_equal SampleModule::sample_method, SampleModule::smple_methd
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require_relative '../lib/frubby'
|
3
|
+
|
4
|
+
class RespondToMissingTest < Minitest::Test
|
5
|
+
def sample_method
|
6
|
+
'test'
|
7
|
+
end
|
8
|
+
|
9
|
+
def sample_method_with_argument(arg)
|
10
|
+
"test #{arg}"
|
11
|
+
end
|
12
|
+
|
13
|
+
module SampleModule
|
14
|
+
def self.sample_method
|
15
|
+
'test'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_missing_method_name
|
20
|
+
assert_equal true, respond_to?(:smple_method)
|
21
|
+
assert_equal true, respond_to?(:sample_mthod)
|
22
|
+
assert_equal true, respond_to?(:sampe_method)
|
23
|
+
assert_equal true, respond_to?(:sampe_mothod)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_missing_method_name_with_argument
|
27
|
+
assert_equal true, respond_to?(:smple_method_with_argmtn)
|
28
|
+
assert_equal true, respond_to?(:smple_meod_with_argmtn)
|
29
|
+
assert_equal true, respond_to?(:smple_method_with_argmtn)
|
30
|
+
assert_equal true, respond_to?(:smple_methd_wth_argmtn)
|
31
|
+
assert_equal true, respond_to?(:smple_method_with_agmtn)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_missing_module_self_method_name
|
35
|
+
assert_equal true, SampleModule.respond_to?(:smple_method)
|
36
|
+
assert_equal true, SampleModule.respond_to?(:smple_metod)
|
37
|
+
assert_equal true, SampleModule.respond_to?(:smple_method)
|
38
|
+
assert_equal true, SampleModule.respond_to?(:smple_ethod)
|
39
|
+
assert_equal true, SampleModule.respond_to?(:smple_methd)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: frubby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michał Kalbarczyk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fuzzy_match
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Ruby String class extension. Adds methods to set text color, background
|
56
|
+
color and, text effects on ruby console and command line output, using ANSI escape
|
57
|
+
sequences.
|
58
|
+
email: fazibear@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- frubby.gemspec
|
68
|
+
- lib/frubby.rb
|
69
|
+
- lib/frubby/const_missing.rb
|
70
|
+
- lib/frubby/method_missing.rb
|
71
|
+
- lib/frubby/respond_to_missing.rb
|
72
|
+
- test.rb
|
73
|
+
- test/test.rb
|
74
|
+
- test/test_const_missing.rb
|
75
|
+
- test/test_method_missing.rb
|
76
|
+
- test/test_respond_to_missing.rb
|
77
|
+
homepage: http://github.com/fazibear/frubby
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.4.5
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Add color methods to String class
|
101
|
+
test_files: []
|