bindless 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +2 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/VERSION +1 -0
- data/bindless.gemspec +22 -0
- data/examples/simple_use_case.rb +20 -0
- data/files.rb +24 -0
- data/lib/bindless/model.rb +59 -0
- data/lib/bindless/object.rb +10 -0
- data/lib/bindless/proc.rb +18 -0
- data/lib/bindless.rb +8 -0
- metadata +55 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ODU5YTA1NTIyMjUxZTM2Y2ViMTAzNDc0YTQ2ZTI2MDVlNWU4MGJiYw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTIzYTUyYTBlMzE0MDU5OTliN2Y0MmU0ZDE1MDcwOGI2NjM2Y2Q3Mg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODFiYjljODU4MmE5ZjhjYTJlNjkwMzBkZjAxNjdkODRjNjQwN2Y4YTEzYWU4
|
10
|
+
M2M1YmE2YjFjODlmZWYyNmI2NjI0ODNlMzNjMTk2ZmNkYTYxMTllZjY1ZTEx
|
11
|
+
M2QxOGI5MDE4YzI4YzE2MjNiMWZhOTlmNzdhNGQ4NjFjNGM5NTA=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NzczMDJjZjUyNDJjMGU1ZWI0NzY0MjA0ZGEzMTBiOWQ4NzdhMzk0ZDIxMDhi
|
14
|
+
ZWVkOTQyNzUwNDZlYmQ0OTQxZjI3NjhhZTAyYjJhNzczNjliMzc5MjgwMDBi
|
15
|
+
Y2JhNWUzZjM5YjY0MjFjYmM2ODE2MGY5MWQ0N2VmYjM0YzhiNTQ=
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
bindless
|
2
|
+
========
|
3
|
+
|
4
|
+
run ruby procs with different binds on the fly!
|
5
|
+
|
6
|
+
simple use
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
|
10
|
+
require "bindless"
|
11
|
+
|
12
|
+
test_proc= Proc.new{
|
13
|
+
self.hello_world
|
14
|
+
}
|
15
|
+
|
16
|
+
class Test
|
17
|
+
|
18
|
+
def self.hello_world
|
19
|
+
puts "hello world!"
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.test_call proc_obj
|
23
|
+
proc_obj.call_with_binding(self.binding?)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
Test.test_call test_proc
|
29
|
+
#> "hello world!"
|
30
|
+
|
31
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join "bundler","gem_tasks"
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/bindless.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__),"files.rb"))
|
4
|
+
|
5
|
+
### Specification for the new Gem
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
|
8
|
+
spec.name = "bindless"
|
9
|
+
spec.version = File.open(File.join(File.dirname(__FILE__),"VERSION")).read.split("\n")[0].chomp.gsub(' ','')
|
10
|
+
spec.authors = ["Adam Luzsi"]
|
11
|
+
spec.email = ["adamluzsi@gmail.com"]
|
12
|
+
spec.description = %q{Run any ruby procs with different binds on the fly!}
|
13
|
+
spec.summary = %q{run ruby procs with different binds on the fly!}
|
14
|
+
spec.homepage = "https://github.com/adamluzsi/asynchronous"
|
15
|
+
#spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = SpecFiles
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative "../lib/bindless"
|
2
|
+
|
3
|
+
test_proc= Proc.new{
|
4
|
+
self.hello_world
|
5
|
+
}
|
6
|
+
|
7
|
+
class Test
|
8
|
+
|
9
|
+
def self.hello_world
|
10
|
+
puts "hello world!"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.test_call proc_obj
|
14
|
+
proc_obj.call_with_binding(self.binding?)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
Test.test_call test_proc
|
20
|
+
#> "hello world!"
|
data/files.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
### Get Files from dir
|
2
|
+
begin
|
3
|
+
|
4
|
+
files_to_be_loaded = %w[version.rb]
|
5
|
+
|
6
|
+
SpecFiles= Array.new
|
7
|
+
|
8
|
+
Dir[File.expand_path(File.join(File.dirname(__FILE__),"**","*"))].sort.uniq.each do |one_file_name|
|
9
|
+
one_file_name = File.expand_path one_file_name
|
10
|
+
file_name = one_file_name[(File.expand_path(File.dirname(__FILE__)).to_s.length+1)..(one_file_name.length-1)]
|
11
|
+
|
12
|
+
if !one_file_name.include?("pkg")
|
13
|
+
if !File.directory? file_name
|
14
|
+
SpecFiles.push file_name
|
15
|
+
STDOUT.puts file_name if $DEBUG
|
16
|
+
if files_to_be_loaded.include? one_file_name.split(File::SEPARATOR).last
|
17
|
+
load one_file_name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Bindless
|
2
|
+
class Model
|
3
|
+
|
4
|
+
def initialize(bindings = [])
|
5
|
+
@bindings = bindings
|
6
|
+
end
|
7
|
+
|
8
|
+
def method_missing(m, *args)
|
9
|
+
@bindings.reverse_each do |bind|
|
10
|
+
begin
|
11
|
+
method = eval("method(%s)" % m.inspect, bind)
|
12
|
+
rescue NameError
|
13
|
+
else
|
14
|
+
return method.call(*args)
|
15
|
+
end
|
16
|
+
begin
|
17
|
+
value = eval(m.to_s, bind)
|
18
|
+
return value
|
19
|
+
rescue NameError
|
20
|
+
end
|
21
|
+
end
|
22
|
+
raise NoMethodError, "No such variable or method: %s" % m
|
23
|
+
end
|
24
|
+
|
25
|
+
def pop_binding
|
26
|
+
@bindings.pop
|
27
|
+
end
|
28
|
+
|
29
|
+
def push_binding(bind)
|
30
|
+
@bindings.push bind
|
31
|
+
end
|
32
|
+
|
33
|
+
def push_instance(obj)
|
34
|
+
@bindings.push obj.instance_eval { binding }
|
35
|
+
end
|
36
|
+
|
37
|
+
def push_hash(vars)
|
38
|
+
push_instance Struct.new(*vars.keys).new(*vars.values)
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_binding
|
42
|
+
instance_eval { binding }
|
43
|
+
end
|
44
|
+
|
45
|
+
def run_proc(p, *args)
|
46
|
+
instance_exec(*args, &p)
|
47
|
+
end
|
48
|
+
|
49
|
+
def push_method(name, p, obj=nil)
|
50
|
+
x = Object.new
|
51
|
+
singleton = class << x; self; end
|
52
|
+
singleton.send(:define_method, name, lambda { |*args|
|
53
|
+
obj.instance_exec(*args, &p)
|
54
|
+
})
|
55
|
+
push_instance x
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Proc
|
2
|
+
|
3
|
+
def call_with_binding(bind, *args)
|
4
|
+
Bindless::Model.new([bind]).run_proc(self, *args)
|
5
|
+
end
|
6
|
+
|
7
|
+
def call_with_obj(obj, *args)
|
8
|
+
m = nil
|
9
|
+
p = self
|
10
|
+
Object.class_eval do
|
11
|
+
define_method :a_temp_method_name, &p
|
12
|
+
m = instance_method :a_temp_method_name
|
13
|
+
remove_method :a_temp_method_name
|
14
|
+
end
|
15
|
+
m.bind(obj).call(*args)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/lib/bindless.rb
ADDED
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bindless
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Luzsi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Run any ruby procs with different binds on the fly!
|
14
|
+
email:
|
15
|
+
- adamluzsi@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- Gemfile
|
21
|
+
- README.md
|
22
|
+
- Rakefile
|
23
|
+
- VERSION
|
24
|
+
- bindless.gemspec
|
25
|
+
- examples/simple_use_case.rb
|
26
|
+
- files.rb
|
27
|
+
- lib/bindless.rb
|
28
|
+
- lib/bindless/model.rb
|
29
|
+
- lib/bindless/object.rb
|
30
|
+
- lib/bindless/proc.rb
|
31
|
+
homepage: https://github.com/adamluzsi/asynchronous
|
32
|
+
licenses: []
|
33
|
+
metadata: {}
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 2.2.1
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: run ruby procs with different binds on the fly!
|
54
|
+
test_files: []
|
55
|
+
has_rdoc:
|