meta_missing 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +84 -0
- data/LICENSE.txt +20 -0
- data/README.md +45 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/lib/meta_missing.rb +59 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bfc89dbc3f07ab6aa715b99ec26a1da224c5e82d
|
4
|
+
data.tar.gz: 7e42dbe828cb28aecc6584756633ab83747257c7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 505de9e57dd88b93e3a919ab6c201e94a14e83ab35d7d6f17607b591e2468cdf059ab055b2c5759d8f11a359e95e56eb3fefc86bec3baa24e384ca83e201153e
|
7
|
+
data.tar.gz: a8102f6c9ae832a58487f0a9720fcb108b1679b823e1353964eb35bc9069a40c7153cf1f50ff89701dae1c8bd0123fb27793fe8a411412e36bc873ead2955f76
|
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem "activesupport", "~> 4.0"
|
6
|
+
gem "patched", "~> 0.0.3"
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "rdoc", "~> 3.12"
|
12
|
+
gem "bundler", "~> 1.0"
|
13
|
+
gem "jeweler", "~> 2.0", ">= 2.0.1"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (4.1.7)
|
5
|
+
i18n (~> 0.6, >= 0.6.9)
|
6
|
+
json (~> 1.7, >= 1.7.7)
|
7
|
+
minitest (~> 5.1)
|
8
|
+
thread_safe (~> 0.1)
|
9
|
+
tzinfo (~> 1.1)
|
10
|
+
addressable (2.3.6)
|
11
|
+
builder (3.2.2)
|
12
|
+
descendants_tracker (0.0.4)
|
13
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
14
|
+
faraday (0.9.0)
|
15
|
+
multipart-post (>= 1.2, < 3)
|
16
|
+
file-tail (1.0.12)
|
17
|
+
tins (~> 0.5)
|
18
|
+
git (1.2.8)
|
19
|
+
github_api (0.12.2)
|
20
|
+
addressable (~> 2.3)
|
21
|
+
descendants_tracker (~> 0.0.4)
|
22
|
+
faraday (~> 0.8, < 0.10)
|
23
|
+
hashie (>= 3.3)
|
24
|
+
multi_json (>= 1.7.5, < 2.0)
|
25
|
+
nokogiri (~> 1.6.3)
|
26
|
+
oauth2
|
27
|
+
hashie (3.3.1)
|
28
|
+
highline (1.6.21)
|
29
|
+
i18n (0.6.11)
|
30
|
+
jeweler (2.0.1)
|
31
|
+
builder
|
32
|
+
bundler (>= 1.0)
|
33
|
+
git (>= 1.2.5)
|
34
|
+
github_api
|
35
|
+
highline (>= 1.6.15)
|
36
|
+
nokogiri (>= 1.5.10)
|
37
|
+
rake
|
38
|
+
rdoc
|
39
|
+
json (1.8.1)
|
40
|
+
jwt (1.0.0)
|
41
|
+
mini_portile (0.6.0)
|
42
|
+
minitest (5.4.2)
|
43
|
+
multi_json (1.10.1)
|
44
|
+
multi_xml (0.5.5)
|
45
|
+
multipart-post (2.0.0)
|
46
|
+
nokogiri (1.6.3.1)
|
47
|
+
mini_portile (= 0.6.0)
|
48
|
+
oauth2 (1.0.0)
|
49
|
+
faraday (>= 0.8, < 0.10)
|
50
|
+
jwt (~> 1.0)
|
51
|
+
multi_json (~> 1.3)
|
52
|
+
multi_xml (~> 0.5)
|
53
|
+
rack (~> 1.2)
|
54
|
+
patched (0.0.3)
|
55
|
+
sourcify (>= 0.6.0.rc4)
|
56
|
+
rack (1.5.2)
|
57
|
+
rake (10.3.2)
|
58
|
+
rdoc (3.12.2)
|
59
|
+
json (~> 1.4)
|
60
|
+
ruby2ruby (1.3.1)
|
61
|
+
ruby_parser (~> 2.0)
|
62
|
+
sexp_processor (~> 3.0)
|
63
|
+
ruby_parser (2.3.1)
|
64
|
+
sexp_processor (~> 3.0)
|
65
|
+
sexp_processor (3.2.0)
|
66
|
+
sourcify (0.6.0.rc4)
|
67
|
+
file-tail (~> 1.0.10)
|
68
|
+
ruby2ruby (~> 1.3.1)
|
69
|
+
ruby_parser (~> 2.3.1)
|
70
|
+
sexp_processor (~> 3.2.0)
|
71
|
+
thread_safe (0.3.4)
|
72
|
+
tins (0.13.2)
|
73
|
+
tzinfo (1.2.2)
|
74
|
+
thread_safe (~> 0.1)
|
75
|
+
|
76
|
+
PLATFORMS
|
77
|
+
ruby
|
78
|
+
|
79
|
+
DEPENDENCIES
|
80
|
+
activesupport (~> 4.0)
|
81
|
+
bundler (~> 1.0)
|
82
|
+
jeweler (~> 2.0, >= 2.0.1)
|
83
|
+
patched (~> 0.0.3)
|
84
|
+
rdoc (~> 3.12)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Evan Senter
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# meta_missing
|
2
|
+
|
3
|
+
require "meta_missing"
|
4
|
+
|
5
|
+
class AnimalFarm
|
6
|
+
prepend MetaMissing
|
7
|
+
|
8
|
+
handle_methods_like(/pony/) do |name, *args, &block|
|
9
|
+
[self, name, args, block_given?, block, block[]]
|
10
|
+
end
|
11
|
+
|
12
|
+
handle_methods_like(/kitties/) do
|
13
|
+
["Meow meow meow", block_given?]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
### And then try the following:
|
18
|
+
|
19
|
+
> AnimalFarm.new.mecha_pony(1, 2, 3) { 4 }
|
20
|
+
> AnimalFarm.new.kitties
|
21
|
+
|
22
|
+
#=> [#<AnimalFarm:0x007fce22b69188>, :mecha_pony, [1, 2, 3], true, #<Proc:0x007fce22b69110@(pry)>, 4]
|
23
|
+
#=> ["Meow meow meow", false]
|
24
|
+
|
25
|
+
### Contrast this with:
|
26
|
+
|
27
|
+
> AnimalFarm.new.pigs
|
28
|
+
|
29
|
+
#=> NoMethodError: undefined method `pigs' for #<Foo:0x007fd74fccab90>
|
30
|
+
|
31
|
+
## Contributing to meta_missing
|
32
|
+
|
33
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
34
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
35
|
+
* Fork the project.
|
36
|
+
* Start a feature/bugfix branch.
|
37
|
+
* Commit and push until you are happy with your contribution.
|
38
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
39
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
40
|
+
|
41
|
+
## Copyright
|
42
|
+
|
43
|
+
Copyright (c) 2014 Evan Senter. See LICENSE.txt for
|
44
|
+
further details.
|
45
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "meta_missing"
|
18
|
+
gem.homepage = "http://github.com/evansenter/meta_missing"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Handle method_missing with ease}
|
21
|
+
gem.description = %Q{A small library to allow metaprogramming via method_missing without dealing with regular expression hell.}
|
22
|
+
gem.email = "evansenter@gmail.com"
|
23
|
+
gem.authors = ["Evan Senter"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Code coverage detail"
|
36
|
+
task :simplecov do
|
37
|
+
ENV['COVERAGE'] = "true"
|
38
|
+
Rake::Task['test'].execute
|
39
|
+
end
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rdoc/task'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "meta_missing #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/meta_missing.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "active_support"
|
2
|
+
require "active_support/core_ext/class/attribute"
|
3
|
+
require "patched"
|
4
|
+
|
5
|
+
module MetaMissing
|
6
|
+
include Patched
|
7
|
+
|
8
|
+
using patched(Proc) {
|
9
|
+
def bind(object)
|
10
|
+
block, time = self, Time.now
|
11
|
+
object.class_eval do
|
12
|
+
method_name = "__bind_#{time.to_i}_#{time.usec}"
|
13
|
+
define_method(method_name, &block)
|
14
|
+
instance_method(method_name).tap do
|
15
|
+
remove_method(method_name)
|
16
|
+
end
|
17
|
+
end.bind(object)
|
18
|
+
end
|
19
|
+
}
|
20
|
+
|
21
|
+
def self.prepended(base)
|
22
|
+
base.class_eval do
|
23
|
+
extend ClassMethods
|
24
|
+
|
25
|
+
class_attribute :method_handlers
|
26
|
+
self.method_handlers = []
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.bind(proc, context)
|
31
|
+
proc.bind(context)
|
32
|
+
end
|
33
|
+
|
34
|
+
def method_missing(name, *args, &block)
|
35
|
+
if handler = method_handlers.find { |handler| handler[:regexp] =~ name.to_s }
|
36
|
+
if block_given?
|
37
|
+
class_eval do
|
38
|
+
alias_method :orig_block_given?, :block_given?
|
39
|
+
def block_given?; true; end
|
40
|
+
end
|
41
|
+
|
42
|
+
MetaMissing.bind(handler[:block], self)[name, *args, &block].tap do
|
43
|
+
class_eval do
|
44
|
+
alias_method :block_given?, :orig_block_given?
|
45
|
+
remove_method :orig_block_given?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
else
|
49
|
+
instance_exec(name, *args, &handler[:block])
|
50
|
+
end
|
51
|
+
else super end
|
52
|
+
end
|
53
|
+
|
54
|
+
module ClassMethods
|
55
|
+
def handle_methods_like(regexp, &block)
|
56
|
+
method_handlers << { regexp: regexp, block: block }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: meta_missing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Evan Senter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: patched
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.12'
|
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.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jeweler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.0.1
|
76
|
+
- - "~>"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '2.0'
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.0.1
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '2.0'
|
89
|
+
description: A small library to allow metaprogramming via method_missing without dealing
|
90
|
+
with regular expression hell.
|
91
|
+
email: evansenter@gmail.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files:
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
files:
|
98
|
+
- ".document"
|
99
|
+
- Gemfile
|
100
|
+
- Gemfile.lock
|
101
|
+
- LICENSE.txt
|
102
|
+
- README.md
|
103
|
+
- Rakefile
|
104
|
+
- VERSION
|
105
|
+
- lib/meta_missing.rb
|
106
|
+
homepage: http://github.com/evansenter/meta_missing
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.4.2
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Handle method_missing with ease
|
130
|
+
test_files: []
|