method_not_missing 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 +22 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +2 -0
- data/lib/method_not_missing/method_searcher.rb +40 -0
- data/lib/method_not_missing/omnipotent_object.rb +11 -0
- data/lib/method_not_missing/version.rb +3 -0
- data/lib/method_not_missing.rb +58 -0
- data/method_not_missing.gemspec +26 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 06147e051c9f300ddf0e41c9c0cb62bfe6b6b8a0
|
4
|
+
data.tar.gz: cc676d94dc391bac66cdb6117709a5275331c571
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 68d0785a3db5e69bd680105b456c67a39af3e855c2e612c4df8a355f6a424a6c6762db2baf4652eb896571edfa0fa8e92772057c5d8a8123c8022057a3403054
|
7
|
+
data.tar.gz: bc0217a33617303934f53707d40375892e484e5be7273602d53918f0bff8662c8ef4ed94879662872824c9e42e464f34e1d3f9b45f4451c53ffb3c9f8615588b
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Jell
|
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,54 @@
|
|
1
|
+
# Method *not* missing
|
2
|
+
|
3
|
+
By including the module `MethodNotMissing`, an object's `method_missing`
|
4
|
+
will be replaced by googling to rdoc and implemented on the
|
5
|
+
fly. Instance variables are added where missing and missing constants
|
6
|
+
are also declared on the fly.
|
7
|
+
|
8
|
+
There's some backtracking if the implementation found raises an error
|
9
|
+
(like stack overflows) or if a nested method lookup fails.
|
10
|
+
|
11
|
+
# Installation
|
12
|
+
|
13
|
+
```sh
|
14
|
+
gem install method_not_missing
|
15
|
+
```
|
16
|
+
|
17
|
+
## External dependencies
|
18
|
+
- PhantomJS ( `brew install phantomjs` on OSX )
|
19
|
+
|
20
|
+
# Warnings
|
21
|
+
|
22
|
+
This is insane.
|
23
|
+
|
24
|
+
# Example
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require "method_not_missing"
|
28
|
+
|
29
|
+
object = MethodNotMissing::OmnipotentObject.new
|
30
|
+
object.update([3])
|
31
|
+
## Googling...
|
32
|
+
#=> [3]
|
33
|
+
object.update([4])
|
34
|
+
#=> [3, 4]
|
35
|
+
object.inspect
|
36
|
+
#=> #<MethodNotMissing::OmnipotentObject:70308021738440 @uncounted=[3, 4]>
|
37
|
+
```
|
38
|
+
|
39
|
+
# Future work:
|
40
|
+
|
41
|
+
- Type Safety: since we get the arity of the requested function, we
|
42
|
+
could filter out the ones with the wrong number of argument. This is
|
43
|
+
implemented with exception-driven backtracking on ArgumentErrors
|
44
|
+
right now.
|
45
|
+
|
46
|
+
- Enterprise
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it ( https://github.com/[my-github-username]/method_not_missing/fork )
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'capybara'
|
3
|
+
require 'capybara/poltergeist'
|
4
|
+
require 'capybara/dsl'
|
5
|
+
|
6
|
+
Capybara.run_server = false
|
7
|
+
Capybara.current_driver = :poltergeist
|
8
|
+
Capybara.default_wait_time = 10
|
9
|
+
Capybara.app_host = "http://www.google.co.uk/"
|
10
|
+
Capybara.ignore_hidden_elements = false
|
11
|
+
|
12
|
+
module MethodNotMissing::MethodSearcher
|
13
|
+
extend self
|
14
|
+
|
15
|
+
def search_method (method_name)
|
16
|
+
puts "searching #{method_name}"
|
17
|
+
@page ||= ::Capybara::Session.new(:poltergeist)
|
18
|
+
@page.visit("http://www.google.co.uk/search")
|
19
|
+
puts "Googling..."
|
20
|
+
|
21
|
+
@page.fill_in "q", with: "\"def #{method_name}\" site:http://www.rubydoc.info/github"
|
22
|
+
|
23
|
+
@page.click_button "Google Search"
|
24
|
+
|
25
|
+
Enumerator.new do |y|
|
26
|
+
links = @page.all("li.g h3").map do |h3|
|
27
|
+
h3.find("a")[:href]
|
28
|
+
end
|
29
|
+
links.each do |url|
|
30
|
+
@page.visit url
|
31
|
+
html_codes = @page.body.scan(/<pre class="code">.*?<\/pre>/m)
|
32
|
+
codes = html_codes.map do |html|
|
33
|
+
CGI::unescapeHTML(html.gsub(/<.*?>/,""))
|
34
|
+
end
|
35
|
+
code = codes.grep(/def #{method_name}/).first
|
36
|
+
y << code if code
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class MethodNotMissing::OmnipotentObject < Array
|
2
|
+
include MethodNotMissing
|
3
|
+
|
4
|
+
def inspect
|
5
|
+
string = "#<#{self.class.name}:#{self.object_id}"
|
6
|
+
instance_variables.each do |var|
|
7
|
+
string += " #{var}=#{instance_variable_get(var)}"
|
8
|
+
end
|
9
|
+
string + ">"
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "method_not_missing/version"
|
2
|
+
require "method_not_missing/omnipotent_object"
|
3
|
+
require "method_not_missing/method_searcher"
|
4
|
+
|
5
|
+
module MethodNotMissing
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def self.included (base)
|
9
|
+
base.extend self
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing (meth, *args)
|
13
|
+
result = nil
|
14
|
+
puts "Missing: #{meth}"
|
15
|
+
args.each { |arg| arg.extend MethodNotMissing rescue nil }
|
16
|
+
found = MethodSearcher.search_method(meth.to_s).detect do |method_body|
|
17
|
+
begin
|
18
|
+
puts "*"*80
|
19
|
+
puts method_body
|
20
|
+
puts "*"*80
|
21
|
+
|
22
|
+
vars = method_body.scan(/@[a-zA-Z0-9_]+/)
|
23
|
+
puts "Vars: #{vars}"
|
24
|
+
vars.each do |var|
|
25
|
+
# We want a class with << because that's a common method and
|
26
|
+
# it can't be found online.
|
27
|
+
object = Class.new(Array) { include MethodNotMissing }.new
|
28
|
+
instance_variable_get(var) or
|
29
|
+
instance_variable_set(var, object)
|
30
|
+
end
|
31
|
+
|
32
|
+
self.class.send(:eval, method_body)
|
33
|
+
result = self.send(meth, *args) do
|
34
|
+
yield
|
35
|
+
end
|
36
|
+
true
|
37
|
+
rescue Exception => e # We wanna rescue stack overflows also
|
38
|
+
puts "Error!"
|
39
|
+
puts e.inspect
|
40
|
+
false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
if found
|
45
|
+
result
|
46
|
+
else
|
47
|
+
super
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def const_missing(name)
|
52
|
+
puts "Missing class #{name}"
|
53
|
+
puts "making it up on the spot"
|
54
|
+
klass = Class.new(OmnipotentObject)
|
55
|
+
const_set(name, klass)
|
56
|
+
klass
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'method_not_missing/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "method_not_missing"
|
8
|
+
spec.version = MethodNotMissing::VERSION
|
9
|
+
spec.authors = ["Jell"]
|
10
|
+
spec.email = ["jean-louis@jawaninja.com"]
|
11
|
+
spec.summary = %q{Implement missing methods by googling their implementation on the fly. Because Ruby.}
|
12
|
+
spec.description = %q{WARNING: CONTAINS TRACES OF SARCASM}
|
13
|
+
spec.homepage = "https://github.com/Jell/method_not_missing"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'poltergeist', '~> 1.5'
|
22
|
+
spec.add_runtime_dependency 'capybara', '~> 2.2'
|
23
|
+
spec.add_runtime_dependency 'launchy', '~> 2.4'
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake", '~> 10.3'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: method_not_missing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: poltergeist
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: capybara
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: launchy
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.4'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.3'
|
83
|
+
description: 'WARNING: CONTAINS TRACES OF SARCASM'
|
84
|
+
email:
|
85
|
+
- jean-louis@jawaninja.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/method_not_missing.rb
|
96
|
+
- lib/method_not_missing/method_searcher.rb
|
97
|
+
- lib/method_not_missing/omnipotent_object.rb
|
98
|
+
- lib/method_not_missing/version.rb
|
99
|
+
- method_not_missing.gemspec
|
100
|
+
homepage: https://github.com/Jell/method_not_missing
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.2.2
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: Implement missing methods by googling their implementation on the fly. Because
|
124
|
+
Ruby.
|
125
|
+
test_files: []
|
126
|
+
has_rdoc:
|