node_module 0.1.0
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.
- data/.gitignore +17 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +83 -0
- data/Rakefile +10 -0
- data/lib/node_module.rb +53 -0
- data/lib/node_module/version.rb +3 -0
- data/node_module.gemspec +26 -0
- data/spec/spec_helper.rb +6 -0
- metadata +143 -0
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Lee Machin
|
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,83 @@
|
|
1
|
+
# node_module
|
2
|
+
|
3
|
+
Ruby is a pretty high level language, so isn't perfectly suited to
|
4
|
+
things such as:
|
5
|
+
|
6
|
+
1. Systems programming
|
7
|
+
2. Being web-scale
|
8
|
+
|
9
|
+
It's also difficult to represent basic concepts in Ruby, as the sheer
|
10
|
+
amount of dynamism and expressivity baked into the language compels
|
11
|
+
the programmer to only think of code in terms of objects and
|
12
|
+
orientation, and Dijkstra. This is way too high level.
|
13
|
+
|
14
|
+
Thankfully, there is a burgeoning language on the scene that empowers
|
15
|
+
the programmer to really think about the nuts and bolts of their
|
16
|
+
implementation. Your code no longer explains to you what you want to
|
17
|
+
happen, but how it should do it.
|
18
|
+
|
19
|
+
Naturally, issuing commands to a computer -- typically in the form of
|
20
|
+
an assembly language, compiled C code, or JavaScript -- allows the
|
21
|
+
program to scale effortlessly under extreme loads, and allows you to reason
|
22
|
+
about what exactly your hardware is doing.
|
23
|
+
|
24
|
+
To that end, this library lets you drop down to JavaScript at the method level,
|
25
|
+
so parts of your class can be executed more efficiently. This makes Ruby *perfectly*
|
26
|
+
suited to things such as:
|
27
|
+
|
28
|
+
1. Systems programming
|
29
|
+
2. Being web-scale
|
30
|
+
|
31
|
+
## How to use
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'node_module'
|
35
|
+
|
36
|
+
class AbstractConcepts
|
37
|
+
|
38
|
+
def existentialism
|
39
|
+
self.name = "me"
|
40
|
+
end
|
41
|
+
|
42
|
+
def solipsism
|
43
|
+
(constants - [self.class]).map(&:remove_const)
|
44
|
+
end
|
45
|
+
|
46
|
+
node_module
|
47
|
+
|
48
|
+
def pythagoras_theorm
|
49
|
+
a, b, c = [3, 4, 5]
|
50
|
+
a**2 + b**2 == c**2
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
Any method you define after `node_module` will be converted to JavaScript before being
|
56
|
+
executed.
|
57
|
+
|
58
|
+
This is a ridiculous proof of concept, so there are a few issues...
|
59
|
+
|
60
|
+
## Caveats
|
61
|
+
|
62
|
+
- Only the body of a method is used, so there is no access to the name
|
63
|
+
or arguments passed.
|
64
|
+
|
65
|
+
- References to the rest of the class will fail, because it all falls
|
66
|
+
out of scope when converted.
|
67
|
+
|
68
|
+
- Node isn't actually being used yet, so calls to `puts` will blow up
|
69
|
+
as V8 doesn't have the `console` object.
|
70
|
+
|
71
|
+
- Probably lots of other stuff I don't know about, because I haven't
|
72
|
+
felt insane enough to check everything out
|
73
|
+
|
74
|
+
## What Ruby code will work?
|
75
|
+
|
76
|
+
Check [Opal](http://opalrb.org) for that. It's what does all the hard work.
|
77
|
+
|
78
|
+
## WHY!??
|
79
|
+
|
80
|
+
> **I'll often drop down to node.js if I really need to be close to the metal**
|
81
|
+
> https://twitter.com/shit_hn_says/status/234856345579446272
|
82
|
+
|
83
|
+
'nuff said.
|
data/Rakefile
ADDED
data/lib/node_module.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require "node_module/version"
|
2
|
+
require 'live_ast/to_ruby'
|
3
|
+
require 'opal'
|
4
|
+
require 'v8'
|
5
|
+
|
6
|
+
module NodeModule
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.extend ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def node_module(*methods)
|
14
|
+
if methods.empty?
|
15
|
+
NodeModule.execute_following_methods_as_javascript!(self)
|
16
|
+
else
|
17
|
+
NodeModule.execute_methods_as_javascript!(methods, self)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module_function
|
23
|
+
|
24
|
+
def self.eval_js(js)
|
25
|
+
@ctx ||= V8::Context.new do |ctx|
|
26
|
+
ctx.eval Opal::Builder.build('opal')
|
27
|
+
end
|
28
|
+
|
29
|
+
@ctx.eval Opal.parse(js)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.execute_methods_as_javascript!(methods, receiver)
|
33
|
+
methods.each do |name|
|
34
|
+
meth = receiver.instance_method(name)
|
35
|
+
body = meth.to_ruby.split("\n")[1..-2].join.strip
|
36
|
+
|
37
|
+
receiver.send :define_method, name do
|
38
|
+
NodeModule.eval_js(body)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.execute_following_methods_as_javascript!(receiver)
|
44
|
+
active = nil
|
45
|
+
receiver.define_singleton_method(:method_added) do |meth_name|
|
46
|
+
return if active
|
47
|
+
active = true
|
48
|
+
receiver.node_module(meth_name)
|
49
|
+
active = false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/node_module.gemspec
ADDED
@@ -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 'node_module/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "node_module"
|
8
|
+
spec.version = NodeModule::VERSION
|
9
|
+
spec.authors = ["Lee Machin"]
|
10
|
+
spec.email = ["lee@new-bamboo.co.uk"]
|
11
|
+
spec.description = %q{Evaluate methods in Ruby as Javascript instead}
|
12
|
+
spec.summary = %q{Get really close to the metal in Ruby}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_dependency "live_ast"
|
22
|
+
spec.add_dependency "therubyracer"
|
23
|
+
spec.add_dependency "opal"
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: node_module
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lee Machin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: live_ast
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: therubyracer
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: opal
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.3'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.3'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Evaluate methods in Ruby as Javascript instead
|
95
|
+
email:
|
96
|
+
- lee@new-bamboo.co.uk
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- .ruby-version
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- lib/node_module.rb
|
108
|
+
- lib/node_module/version.rb
|
109
|
+
- node_module.gemspec
|
110
|
+
- spec/spec_helper.rb
|
111
|
+
homepage: ''
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
hash: -3867090681638509308
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ! '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
hash: -3867090681638509308
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 1.8.23
|
139
|
+
signing_key:
|
140
|
+
specification_version: 3
|
141
|
+
summary: Get really close to the metal in Ruby
|
142
|
+
test_files:
|
143
|
+
- spec/spec_helper.rb
|