node.rb 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.
- data/.document +5 -0
- data/.gitignore +31 -0
- data/LICENSE +20 -0
- data/README.rdoc +54 -0
- data/Rakefile +81 -0
- data/VERSION +1 -0
- data/bin/node-rb +8 -0
- data/ext/ruby/extconf.h +4 -0
- data/ext/ruby/extconf.rb +40 -0
- data/ext/ruby/node/common.h +15 -0
- data/ext/ruby/node/node_wrapper.cpp +14 -0
- data/ext/ruby/node/ruby.cpp +34 -0
- data/ext/ruby/node/ruby18.cpp +12 -0
- data/ext/ruby/node/ruby19.cpp +14 -0
- data/ext/ruby/ruby/ruby.cpp +9 -0
- data/ext/ruby/wscript.rb.erb +68 -0
- data/lib/node.rb +82 -0
- data/lib/node.rb.rb +1 -0
- data/lib/node_rb.rb +1 -0
- data/spec/lib/noderb_spec.rb +7 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/support/nodes/context.js +2 -0
- metadata +101 -0
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## PROJECT::GENERAL
|
17
|
+
coverage
|
18
|
+
rdoc
|
19
|
+
pkg
|
20
|
+
|
21
|
+
## PROJECT::SPECIFIC
|
22
|
+
build
|
23
|
+
Makefile
|
24
|
+
mkmf.log
|
25
|
+
.lock-wscript
|
26
|
+
*.node
|
27
|
+
.idea
|
28
|
+
*.so
|
29
|
+
*.o
|
30
|
+
wscript
|
31
|
+
*.bundle
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Colin MacKenzie IV
|
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.rdoc
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
= node.rb
|
2
|
+
|
3
|
+
Embeds a Ruby interpreter (www.ruby-lang.org) into Node.js (www.nodejs.org) for your coding pleasure.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
gem install node.rb
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
To create a Ruby context within your node.js application, do so like this:
|
12
|
+
|
13
|
+
var ruby = require('ruby');
|
14
|
+
ruby.eval('p 1+1');
|
15
|
+
|
16
|
+
== Execution
|
17
|
+
|
18
|
+
For your convenience, the node.rb gem ships with an executable so that you can just:
|
19
|
+
node-rb filename.js
|
20
|
+
|
21
|
+
To execute with the stock node.js executable:
|
22
|
+
NODE_PATH=$NODE_PATH:path/to/node.rb node filename.js
|
23
|
+
|
24
|
+
NODE_PATH is a standard option in node.js and is a simple environment variable. That means you can do this:
|
25
|
+
|
26
|
+
export NODE_PATH=$NODE_PATH:path/to/node.rb
|
27
|
+
node filename.js
|
28
|
+
|
29
|
+
And finally, though I'm not sure why you'd want to do this, you can invoke Node from within Ruby:
|
30
|
+
|
31
|
+
require 'node-rb'
|
32
|
+
n = Node.new("path/to/javascript.js")
|
33
|
+
n.run
|
34
|
+
|
35
|
+
That's roughly equivalent to running the node-rb command directly.
|
36
|
+
|
37
|
+
== Roadmap
|
38
|
+
|
39
|
+
There are plans to expose Node to Ruby and vice versa so that objects can travel between the two contexts,
|
40
|
+
but that's not available at this time.
|
41
|
+
|
42
|
+
== Note on Patches/Pull Requests
|
43
|
+
|
44
|
+
* Fork the project.
|
45
|
+
* Make your feature addition or bug fix.
|
46
|
+
* Add tests for it. This is important so I don't break it in a
|
47
|
+
future version unintentionally.
|
48
|
+
* Commit, do not mess with rakefile, version, or history.
|
49
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
50
|
+
* Send me a pull request. Bonus points for topic branches.
|
51
|
+
|
52
|
+
== Copyright
|
53
|
+
|
54
|
+
Copyright (c) 2010 Colin MacKenzie IV. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "node.rb"
|
8
|
+
gem.summary = %Q{Embeds a Ruby interpreter (www.ruby-lang.org) into Node.js (www.nodejs.org) for your coding pleasure.}
|
9
|
+
gem.description = %Q{Embeds a Ruby interpreter (www.ruby-lang.org) into Node.js (www.nodejs.org) for your coding pleasure.}
|
10
|
+
gem.email = "sinisterchipmunk@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/sinisterchipmunk/node.rb"
|
12
|
+
gem.authors = ["Colin MacKenzie IV"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
begin
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_opts = ["-c"]
|
26
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
end
|
28
|
+
|
29
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
30
|
+
spec.libs << 'lib' << 'spec'
|
31
|
+
spec.spec_opts = ["-c"]
|
32
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
33
|
+
spec.rcov = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
require 'rspec/core/rake_task'
|
37
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
38
|
+
spec.spec_opts = ["-c"]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def each_extension(&block)
|
43
|
+
Dir[File.join(File.dirname(__FILE__), "ext/*")].each do |path|
|
44
|
+
chdir path, &block
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "make extensions"
|
49
|
+
task :make do
|
50
|
+
each_extension do
|
51
|
+
system("ruby extconf.rb") && system("make") || raise("make failed")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
namespace :make do
|
56
|
+
desc "make clean"
|
57
|
+
task :clean do
|
58
|
+
Dir['*.node'].each { |f| rm f }
|
59
|
+
each_extension do
|
60
|
+
system("make clean")
|
61
|
+
%w(build .lock-wscript wscript Makefile).each do |fi|
|
62
|
+
system("find . -name \"#{fi}\" -exec rm -rf {} \\;")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
task :spec => [:check_dependencies, :make]
|
69
|
+
task :clean => 'make:clean'
|
70
|
+
|
71
|
+
task :default => :spec
|
72
|
+
|
73
|
+
require 'rake/rdoctask'
|
74
|
+
Rake::RDocTask.new do |rdoc|
|
75
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
76
|
+
|
77
|
+
rdoc.rdoc_dir = 'rdoc'
|
78
|
+
rdoc.title = "node.rb #{version}"
|
79
|
+
rdoc.rdoc_files.include('README*')
|
80
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
81
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/node-rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.join(File.dirname(__FILE__), "../lib/node")
|
3
|
+
node = Node.new(*ARGV)
|
4
|
+
|
5
|
+
# node.run executes invokes node.js but collects the output; the user will expect
|
6
|
+
# the output in stdout when invoking this script so we have to do it this
|
7
|
+
# way instead
|
8
|
+
system node.command
|
data/ext/ruby/extconf.h
ADDED
data/ext/ruby/extconf.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
require 'erb'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
this_dir = File.expand_path(File.dirname(__FILE__))
|
6
|
+
$LIBS << " -lstdc++"
|
7
|
+
include FileUtils
|
8
|
+
|
9
|
+
##find_header('node.h')
|
10
|
+
#find_header('node/v8.h')
|
11
|
+
$defs << "-DRUBY_VERSION=#{RUBY_VERSION}"
|
12
|
+
|
13
|
+
create_header
|
14
|
+
create_makefile('ruby', File.join(this_dir, "ruby"))
|
15
|
+
|
16
|
+
if RUBY_VERSION < "1.9.0"
|
17
|
+
version_specific_source = "ruby18.cpp"
|
18
|
+
else
|
19
|
+
version_specific_source = "ruby19.cpp"
|
20
|
+
end
|
21
|
+
|
22
|
+
erb = ERB.new(File.read(File.join(File.dirname(__FILE__), "wscript.rb.erb")))
|
23
|
+
|
24
|
+
File.open(File.join(this_dir, "node/wscript"), "w") do |file|
|
25
|
+
srcdir = File.join this_dir, 'node'
|
26
|
+
blddir = File.join this_dir, 'node/build'
|
27
|
+
version = File.read(File.join(this_dir, "../../VERSION")).strip
|
28
|
+
|
29
|
+
file.puts erb.result(binding)
|
30
|
+
end
|
31
|
+
|
32
|
+
Dir.chdir File.join(this_dir, "node") do
|
33
|
+
cmd = "node-waf configure build"
|
34
|
+
system(cmd) || raise("Could not build extension for node.js!")
|
35
|
+
end
|
36
|
+
|
37
|
+
ruby_node = Dir[File.join(this_dir, "**/ruby.node")].reject { |s| s =~ /\.svn/ }.shift
|
38
|
+
raise "Couldn't find newly-generated ruby.node!" unless ruby_node
|
39
|
+
destination = File.join(this_dir, "../..")
|
40
|
+
cp(ruby_node, destination)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#ifndef NODE_RB_COMMON_H
|
2
|
+
#define NODE_RB_COMMON_H
|
3
|
+
|
4
|
+
#include "../extconf.h"
|
5
|
+
#include <v8.h>
|
6
|
+
|
7
|
+
using namespace v8;
|
8
|
+
|
9
|
+
#define ToCString(value) (*value ? *value : "<string conversion failed>")
|
10
|
+
|
11
|
+
extern void init_ruby(void);
|
12
|
+
|
13
|
+
extern Handle<Value> ruby_eval(const Arguments &args);
|
14
|
+
|
15
|
+
#endif//NODE_RB_COMMON_H
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#include <node.h>
|
2
|
+
#include "common.h"
|
3
|
+
|
4
|
+
using namespace node;
|
5
|
+
|
6
|
+
extern "C" void init(Handle<Object> target)
|
7
|
+
{
|
8
|
+
init_ruby();
|
9
|
+
|
10
|
+
HandleScope scope;
|
11
|
+
Handle<Function> eval_func = FunctionTemplate::New(ruby_eval)->GetFunction();
|
12
|
+
eval_func->SetName(String::New("eval"));
|
13
|
+
target->Set(String::New("eval"), eval_func);
|
14
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include "common.h"
|
3
|
+
|
4
|
+
extern "C"
|
5
|
+
void Init_ruby(void) {
|
6
|
+
/* not used at this time */
|
7
|
+
}
|
8
|
+
|
9
|
+
/* protected ruby_eval function, this is always wrapped with rb_protect */
|
10
|
+
static VALUE p_ruby_eval(VALUE code)
|
11
|
+
{
|
12
|
+
return rb_eval_string(StringValuePtr(code));
|
13
|
+
}
|
14
|
+
|
15
|
+
Handle<Value> ruby_eval(const Arguments &args)
|
16
|
+
{
|
17
|
+
if (args.Length() != 1) return ThrowException(String::New("Expected 1 argument"));
|
18
|
+
String::Utf8Value code(Handle<String>::Cast(args[0]));
|
19
|
+
|
20
|
+
int error;
|
21
|
+
VALUE ruby_code = rb_str_new2(ToCString(code));
|
22
|
+
VALUE result = rb_protect(p_ruby_eval, ruby_code, &error);
|
23
|
+
|
24
|
+
if (error)
|
25
|
+
{
|
26
|
+
VALUE message = rb_funcall(rb_gv_get("$!"), rb_intern("message"), 0);
|
27
|
+
return ThrowException(String::New(StringValuePtr(message)));
|
28
|
+
}
|
29
|
+
|
30
|
+
// TODO translate Ruby into JS using Tomato!
|
31
|
+
VALUE message = rb_funcall(result, rb_intern("inspect"), 0);
|
32
|
+
char *ptr = StringValuePtr(message);
|
33
|
+
return String::New(ptr);
|
34
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include "common.h"
|
3
|
+
|
4
|
+
/* This file initializes Ruby when compiled against 1.8.x header files. */
|
5
|
+
|
6
|
+
void init_ruby(void)
|
7
|
+
{
|
8
|
+
RUBY_INIT_STACK
|
9
|
+
ruby_init();
|
10
|
+
// FIXME: a Ruby error causes a segfault. This is because we aren't wrapping with rb_protect and re-raising in Node.
|
11
|
+
// rb_funcall(rb_cObject, rb_intern("puts"), 1, rb_str_new2("Ruby initialized from within node.js"));
|
12
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include "common.h"
|
3
|
+
|
4
|
+
/* This file initializes Ruby when compiled against 1.9.x header files. */
|
5
|
+
|
6
|
+
RUBY_GLOBAL_SETUP
|
7
|
+
void init_ruby(void)
|
8
|
+
{
|
9
|
+
RUBY_INIT_STACK;
|
10
|
+
ruby_init();
|
11
|
+
|
12
|
+
// FIXME: a Ruby error causes a segfault. This is because we aren't wrapping with rb_protect and re-raising in Node.
|
13
|
+
// rb_funcall(rb_cObject, rb_intern("puts"), 1, rb_str_new2("Ruby initialized from within node.js"));
|
14
|
+
}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
import os
|
2
|
+
import Options
|
3
|
+
|
4
|
+
srcdir = '<%=srcdir%>'
|
5
|
+
blddir = '<%=blddir%>'
|
6
|
+
VERSION = '<%=version%>'
|
7
|
+
|
8
|
+
def set_options(opt):
|
9
|
+
opt.tool_options('compiler_cxx')
|
10
|
+
opt.add_option('--with-ruby-archdir', type='string', dest='rubyarchdir', help='Specify directory where to install arch specific files')
|
11
|
+
opt.add_option('--with-ruby-libdir', type='string', dest='rubylibdir', help='Specify alternate ruby library path')
|
12
|
+
|
13
|
+
def configure(conf):
|
14
|
+
conf.check_tool('compiler_cxx')
|
15
|
+
conf.check_tool('node_addon')
|
16
|
+
|
17
|
+
archdir = ['<%=Config::expand CONFIG['archdir']%>']
|
18
|
+
cpppath = archdir
|
19
|
+
<%if RUBY_VERSION >= "1.9.0"%>
|
20
|
+
ruby_hdrdir = ['<%=Config::expand CONFIG['rubyhdrdir']%>']
|
21
|
+
cpppath += ruby_hdrdir
|
22
|
+
cpppath += [os.path.join(ruby_hdrdir[0], '<%=Config::expand CONFIG['arch']%>')]
|
23
|
+
<%end%>
|
24
|
+
|
25
|
+
conf.env.CPPPATH_RUBY += cpppath
|
26
|
+
conf.env.LIB_RUBY = 'ruby'
|
27
|
+
conf.env.LIBPATH_RUBY = ['<%=Config::expand CONFIG['libdir']%>']
|
28
|
+
conf.env.LIBPATH_RUBY += archdir
|
29
|
+
|
30
|
+
conf.check(header_name="ruby.h", includes=cpppath, errmsg='could not find ruby header file')
|
31
|
+
conf.env.CCFLAGS_RUBY += ['<%=Config::expand CONFIG['CCDLFLAGS']%>']
|
32
|
+
conf.env.shlib_PATTERN = '%s.<%=Config::expand CONFIG['DLEXT']%>'
|
33
|
+
|
34
|
+
# ok this is really stupid, but the command and flags are combined.
|
35
|
+
# so we try to find the first argument...
|
36
|
+
flags = <%=(Config::expand CONFIG['LDSHARED']).split.inspect%>
|
37
|
+
|
38
|
+
while flags and flags[0][0] != '-':
|
39
|
+
flags = flags[1:]
|
40
|
+
|
41
|
+
# we also want to strip out the deprecated ppc flags
|
42
|
+
if len(flags) > 1 and flags[1] == "ppc":
|
43
|
+
flags = flags[2:]
|
44
|
+
|
45
|
+
conf.env.LINKFLAGS_RUBYEXT = flags
|
46
|
+
conf.env.LINKFLAGS_RUBYEXT += ['<%=Config::expand CONFIG['LIBS']%>']
|
47
|
+
conf.env.LINKFLAGS_RUBYEXT += ['<%=Config::expand CONFIG['LIBRUBYARG_SHARED']%>']
|
48
|
+
|
49
|
+
if Options.options.rubyarchdir:
|
50
|
+
conf.env.ARCHDIR_RUBY = Options.options.rubyarchdir
|
51
|
+
else:
|
52
|
+
conf.env.ARCHDIR_RUBY = '<%=Config::expand CONFIG['sitearchdir']%>'
|
53
|
+
|
54
|
+
if Options.options.rubylibdir:
|
55
|
+
conf.env.LIBDIR_RUBY = Options.options.rubylibdir
|
56
|
+
else:
|
57
|
+
conf.env.LIBDIR_RUBY = '<%=Config::expand CONFIG['sitelibdir']%>'
|
58
|
+
|
59
|
+
def build(bld):
|
60
|
+
obj1 = bld.new_task_gen('cxx', 'objects', 'node_addon')
|
61
|
+
obj1.target = 'wrapper'
|
62
|
+
obj1.source = 'node_wrapper.cpp'
|
63
|
+
|
64
|
+
ruby = bld.new_task_gen('cxx', 'shlib', 'node_addon')
|
65
|
+
ruby.target = 'ruby'
|
66
|
+
ruby.source = 'ruby.cpp <%=version_specific_source%>'
|
67
|
+
ruby.add_objects = 'wrapper'
|
68
|
+
ruby.uselib = 'RUBY'
|
data/lib/node.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
ENV['LD_LIBRARY_PATH'] ||= Config::expand(Config::CONFIG['libdir'])
|
3
|
+
require File.join(File.dirname(__FILE__), "../ext/ruby/ruby")
|
4
|
+
|
5
|
+
class Node
|
6
|
+
# the value of NODE_PATH. This is an array.
|
7
|
+
attr_accessor :path
|
8
|
+
|
9
|
+
# the name of the stock node.js executable, which is normally just "node"
|
10
|
+
attr_accessor :exec_name
|
11
|
+
|
12
|
+
# If true, prints additional debug output. Defaults to false.
|
13
|
+
attr_accessor :node_debug
|
14
|
+
|
15
|
+
# If set true, loads modules in their own global contexts.
|
16
|
+
attr_accessor :module_contexts
|
17
|
+
|
18
|
+
# Array of command-line arguments for node.js.
|
19
|
+
attr_accessor :opts
|
20
|
+
|
21
|
+
def initialize(file)
|
22
|
+
@file = file
|
23
|
+
@path = default_node_path
|
24
|
+
@exec_name = "node"
|
25
|
+
@node_debug = false
|
26
|
+
@module_contexts = false
|
27
|
+
@opts = []
|
28
|
+
end
|
29
|
+
|
30
|
+
def run
|
31
|
+
%x[#{command}].strip
|
32
|
+
end
|
33
|
+
|
34
|
+
# Constructs the execution command.
|
35
|
+
def command
|
36
|
+
parts = [construct_path, construct_debug, construct_contexts, construct_name, construct_opts, @file]
|
37
|
+
parts.reject { |a| a.nil? || a.length == 0 }.join " "
|
38
|
+
end
|
39
|
+
|
40
|
+
class << self
|
41
|
+
# Returns the path to the node.rb gem.
|
42
|
+
def path_to_gem
|
43
|
+
File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns the path to the node.rb gem.
|
48
|
+
def path_to_gem
|
49
|
+
self.class.path_to_gem
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
def construct_path
|
54
|
+
path.empty? ? "" : "NODE_PATH=#{path.join(":")}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def construct_debug
|
58
|
+
node_debug ? "NODE_DEBUG" : ""
|
59
|
+
end
|
60
|
+
|
61
|
+
def construct_contexts
|
62
|
+
module_contexts ? "NODE_MODULE_CONTEXTS=1" : ""
|
63
|
+
end
|
64
|
+
|
65
|
+
def construct_name
|
66
|
+
exec_name
|
67
|
+
end
|
68
|
+
|
69
|
+
def construct_opts
|
70
|
+
opts.join(" ")
|
71
|
+
end
|
72
|
+
|
73
|
+
def default_node_path
|
74
|
+
path = [path_to_gem] # for node.rb extensions
|
75
|
+
if ENV['NODE_PATH']
|
76
|
+
path.unshift ENV['NODE_PATH']
|
77
|
+
else
|
78
|
+
path.unshift "$NODE_PATH"
|
79
|
+
end
|
80
|
+
path
|
81
|
+
end
|
82
|
+
end
|
data/lib/node.rb.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "node")
|
data/lib/node_rb.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "node")
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
module NodeExecution
|
5
|
+
def node(filename)
|
6
|
+
node = Node.new(File.join(File.dirname(__FILE__), "support/nodes", "#{filename}.js"))
|
7
|
+
puts "Executing:\n #{node.command}"
|
8
|
+
node.run
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
begin
|
13
|
+
require 'spec'
|
14
|
+
require 'spec/autorun'
|
15
|
+
require 'node-rb'
|
16
|
+
|
17
|
+
Spec::Runner.configure do |config|
|
18
|
+
config.include NodeExecution
|
19
|
+
end
|
20
|
+
rescue LoadError
|
21
|
+
require 'rspec'
|
22
|
+
require 'node-rb'
|
23
|
+
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.include NodeExecution
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: node.rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Colin MacKenzie IV
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-09-01 00:00:00 -04:00
|
18
|
+
default_executable: node-rb
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 2
|
31
|
+
- 9
|
32
|
+
version: 1.2.9
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Embeds a Ruby interpreter (www.ruby-lang.org) into Node.js (www.nodejs.org) for your coding pleasure.
|
36
|
+
email: sinisterchipmunk@gmail.com
|
37
|
+
executables:
|
38
|
+
- node-rb
|
39
|
+
extensions:
|
40
|
+
- ext/ruby/extconf.rb
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- bin/node-rb
|
52
|
+
- ext/ruby/extconf.h
|
53
|
+
- ext/ruby/extconf.rb
|
54
|
+
- ext/ruby/node/common.h
|
55
|
+
- ext/ruby/node/node_wrapper.cpp
|
56
|
+
- ext/ruby/node/ruby.cpp
|
57
|
+
- ext/ruby/node/ruby18.cpp
|
58
|
+
- ext/ruby/node/ruby19.cpp
|
59
|
+
- ext/ruby/ruby/ruby.cpp
|
60
|
+
- ext/ruby/wscript.rb.erb
|
61
|
+
- lib/node.rb
|
62
|
+
- lib/node.rb.rb
|
63
|
+
- lib/node_rb.rb
|
64
|
+
- spec/lib/noderb_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
- spec/support/nodes/context.js
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://github.com/sinisterchipmunk/node.rb
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options:
|
73
|
+
- --charset=UTF-8
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
requirements: []
|
93
|
+
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 1.3.7
|
96
|
+
signing_key:
|
97
|
+
specification_version: 3
|
98
|
+
summary: Embeds a Ruby interpreter (www.ruby-lang.org) into Node.js (www.nodejs.org) for your coding pleasure.
|
99
|
+
test_files:
|
100
|
+
- spec/lib/noderb_spec.rb
|
101
|
+
- spec/spec_helper.rb
|