magic_send 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rvmrc +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/magic_send.rb +67 -0
- data/lib/magic_send/version.rb +3 -0
- data/magic_send.gemspec +21 -0
- metadata +76 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jon Phenow
|
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,29 @@
|
|
1
|
+
# MagicSend
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'magic_send'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install magic_send
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/magic_send.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require "magic_send/version"
|
2
|
+
|
3
|
+
class Object
|
4
|
+
def magic_send(*args)
|
5
|
+
MagicSend::MagicSender.magic self, args
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module MagicSend
|
10
|
+
class MagicSender
|
11
|
+
private
|
12
|
+
attr_accessor :object
|
13
|
+
attr_accessor :tries
|
14
|
+
attr_accessor :args
|
15
|
+
|
16
|
+
public
|
17
|
+
|
18
|
+
def self.magic(obj, args)
|
19
|
+
new(obj, args).wave_wand
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(object, args)
|
23
|
+
self.object = object
|
24
|
+
self.args = args
|
25
|
+
self.tries = 0
|
26
|
+
self.method = get_method
|
27
|
+
end
|
28
|
+
|
29
|
+
def wave_wand
|
30
|
+
call
|
31
|
+
end
|
32
|
+
|
33
|
+
def call
|
34
|
+
too_many? ? blow_up : object.send(method, *args)
|
35
|
+
rescue ArgumentError
|
36
|
+
try_again
|
37
|
+
call
|
38
|
+
end
|
39
|
+
private :call
|
40
|
+
|
41
|
+
def too_many?
|
42
|
+
tries > 200
|
43
|
+
end
|
44
|
+
private :too_many?
|
45
|
+
|
46
|
+
def blow_up
|
47
|
+
puts "Your magic needs some work. Please try again."
|
48
|
+
end
|
49
|
+
private :blow_up
|
50
|
+
|
51
|
+
def try_again
|
52
|
+
self.tries += 1
|
53
|
+
self.method = get_method
|
54
|
+
end
|
55
|
+
private :try_again
|
56
|
+
|
57
|
+
def get_method
|
58
|
+
object.methods.sample
|
59
|
+
end
|
60
|
+
private
|
61
|
+
|
62
|
+
def arity
|
63
|
+
method.arity
|
64
|
+
end
|
65
|
+
private :arity
|
66
|
+
end
|
67
|
+
end
|
data/magic_send.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'magic_send/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "magic_send"
|
8
|
+
gem.version = MagicSend::VERSION
|
9
|
+
gem.authors = ["Jon Phenow"]
|
10
|
+
gem.email = ["j.phenow@gmail.com"]
|
11
|
+
gem.description = %q{Do YOU hate deciding what method to call? Me neither}
|
12
|
+
gem.summary = %q{Never worry about the code your calling. EVER AGAIN.}
|
13
|
+
gem.homepage = "http://github.com/jphenow/magic_send"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "rake"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: magic_send
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jon Phenow
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
none: false
|
21
|
+
prerelease: false
|
22
|
+
name: rake
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ! '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
none: false
|
29
|
+
type: :development
|
30
|
+
description: Do YOU hate deciding what method to call? Me neither
|
31
|
+
email:
|
32
|
+
- j.phenow@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- .rvmrc
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- lib/magic_send.rb
|
44
|
+
- lib/magic_send/version.rb
|
45
|
+
- magic_send.gemspec
|
46
|
+
homepage: http://github.com/jphenow/magic_send
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
hash: -3943415062166160276
|
60
|
+
none: false
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
hash: -3943415062166160276
|
69
|
+
none: false
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.24
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Never worry about the code your calling. EVER AGAIN.
|
76
|
+
test_files: []
|