rbridge 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -2,7 +2,4 @@ Original Creator:
2
2
  Toshiyuki Hirooka <toshi.hirooka@gmail.com
3
3
 
4
4
  Additional Patches and English Translation by:
5
- Chuck Vose <vosechu@gmail.com>
6
-
7
- Additional Patches and Windows Testing by:
8
- Sean Steiger-McRae <larreh@gmail.com>
5
+ Chuck Vose <vosechu@gmail.com>
@@ -1,3 +1,12 @@
1
+ == 0.2.0 / 2008-04-24 (vosechu)
2
+ * 1 major enhancement
3
+ * Actually runs headless via the rulang command.
4
+
5
+ * 3 minor enhancements
6
+ * Uses optparse for clearer command-line options.
7
+ * Option to specify port, compile directory, mnesia directory, sname, and location of server file.
8
+ * Some error checking, and debug output added. Checks to see if server is already running on specified port.
9
+
1
10
  == 0.1.2 / 2008-01-10 (vosechu)
2
11
  * major enhancements
3
12
  * Runs headless by using the rulang command or via the command-line using the
@@ -1,14 +1,14 @@
1
- .DS_Store
2
1
  Authors.txt
3
2
  GPL.txt
4
3
  History.txt
5
4
  Manifest.txt
6
5
  README.txt
7
6
  Rakefile
7
+ Todo.txt
8
8
  bin/rulang
9
9
  lib/erlang_adapter.rb
10
+ lib/mnesia_adapter.rb
10
11
  lib/rbridge.rb
11
- lib/vosetools.rb
12
- rulang_server/rulang
12
+ rulang_server/rulang.erl
13
13
  spec/rulang_spec.rb
14
14
  spec/spec_helper.rb
data/README.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  rbridge
2
2
  ruby-mnesia.rubyforge.com
3
- by Toshiyuki Hirooka, Chuck Vose, Sean Steiger-McRae
3
+ by Toshiyuki Hirooka, Chuck Vose
4
4
 
5
5
  == DESCRIPTION:
6
6
 
@@ -55,7 +55,7 @@ more expressive or complex code is needed.
55
55
 
56
56
  RBridge - A Ruby to Erlang bridge allowing the use of Erlang commands within
57
57
  normal Ruby code.
58
- Copyright (C) 2008 Toshiyuki Hirooka <toshi.hirooka@gmail.com>
58
+ Copyright (C) 2008 Toshiyuki Hirooka <toshi.hirooka@gmail.com>, Chuck Vose <vosechu@gmail.com>
59
59
 
60
60
  This program is free software; you can redistribute it and/or
61
61
  modify it under the terms of the GNU General Public License
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require './lib/rbridge.rb'
6
6
 
7
7
  Hoe.new('rbridge', RBridge::VERSION) do |p|
8
8
  p.rubyforge_name = 'ruby-mnesia'
9
- p.author = ['Chuck Vose', 'Toshiyuki Hirooka', 'Sean Steiger-McRae']
9
+ p.author = ['Chuck Vose', 'Toshiyuki Hirooka']
10
10
  p.email = 'vosechu@gmail.com'
11
11
  p.summary = 'RBridge allows the use of Erlang code within the Ruby environment'
12
12
  p.description = p.paragraphs_of('README.txt', 1..4).join("\n\n")
@@ -0,0 +1,6 @@
1
+ - Get the erlang adaptor to handle hashes
2
+ - Add error checking to the rulang server for things like servers already running on a port.
3
+ - Build more tests, specifically the standard CRUD and a few join queries.
4
+ - database.yml should say where beam/mnesia live
5
+ - make record files importable (via rr command)
6
+ - make sure when we start mnesia it's not just running over an old mnesia instance.
data/bin/rulang CHANGED
@@ -1,4 +1,68 @@
1
- #!/usr/local/bin/ruby -ws
1
+ #!/usr/local/bin/ruby -w
2
2
 
3
- server_path = File.expand_path(File.join(File.dirname(__FILE__), "..", "rulang_server"))
4
- exec "escript #{File.join(server_path, "rulang")}"
3
+ require 'optparse'
4
+
5
+ options = {}
6
+ OptionParser.new do |opts|
7
+ opts.banner = "Usage: rulang [options]"
8
+
9
+ # Default of port 9900 and compiling the beam in the same folder as the erlang file.
10
+ options[:port] = 9900
11
+ options[:server_path] = File.expand_path(File.join(File.dirname(__FILE__), "..", "rulang_server"))
12
+ options[:beam_path] = options[:server_path]
13
+
14
+ opts.on("-v", "--verbose", "Run verbosely") do |v|
15
+ options[:verbose] = v
16
+ end
17
+ opts.on("-q", "--quiet", "Run quietly") do |q|
18
+ options[:quiet] = q
19
+ end
20
+ opts.on("-p", "--port Port", "Port Number to Connect To") do |p|
21
+ options[:port] = p
22
+ end
23
+ opts.on("-o", "--beam-path Path", "Path to Compile To") do |o|
24
+ options[:beam_path] = File.expand_path(o)
25
+ end
26
+ opts.on("-m", "--mnesia-path Path", "Path to Mnesia Directory") do |m|
27
+ options[:mnesia_path] = m
28
+ end
29
+ opts.on("-s", "--sname", "Node Name for Clustering") do |s|
30
+ options[:sname] = s
31
+ end
32
+ opts.on("--server-path", "Path to rulang.erl") do |sp|
33
+ options[:server_path] = sp
34
+ end
35
+
36
+ opts.on_tail("-h", "--help", "Show this message") do
37
+ puts opts
38
+ exit
39
+ end
40
+
41
+ opts.on_tail("--version", "Show version") do
42
+ puts OptionParser::Version.join('.')
43
+ exit
44
+ end
45
+ end.parse!
46
+
47
+ # Find out if there's already a beam file on this port
48
+ pid = `ps ax | grep beam | grep -v grep | grep 'rulang:main(\\\[#{options[:port]}\\\])'`
49
+ if pid && !pid.empty?
50
+ puts "Server already running on #{options[:port]}"
51
+ exit
52
+ end
53
+
54
+ # Commands to execute
55
+ compile = "erlc -o #{options[:beam_path]} #{File.join(options[:server_path], "rulang.erl")}"
56
+ start = "cd #{options[:beam_path]}; erl #{"-sname #{options[:sname]}" if options[:sname]} -detached -mnesia #{"dir '\"#{options[:mnesia_path]}\"'" if options[:mnesia_path]} -eval 'rulang:main([#{options[:port]}])'"
57
+
58
+ # Debug output
59
+ puts "Commands", compile, start if ENV['DEBUG'] == 'true'
60
+
61
+ puts "[Rulang Server]\n" unless options[:quiet]
62
+ puts "Compiling rulang beam...\n" if options[:verbose]
63
+ `#{compile}`
64
+ puts "Starting rulang server...\n" if options[:verbose]
65
+ `#{start}`
66
+ puts "Compile path: '#{options[:beam_path]}'\n" if options[:verbose]
67
+ puts "Mnesia path: '#{File.expand_path(options[:mnesia_path])}'\n" if options[:mnesia_path] && options[:verbose]
68
+ puts "PID: " + `ps ax | grep beam | grep -v grep | tail -n1 | cut -f 2 -d " "` if options[:verbose]
@@ -1,6 +1,6 @@
1
1
  # RBridge - A Ruby to Erlang bridge allowing the use of Erlang commands within
2
2
  # normal Ruby code.
3
- # Copyright (C) 2008 Toshiyuki Hirooka <toshi.hirooka@gmail.com>
3
+ # Copyright (C) 2008 Toshiyuki Hirooka <toshi.hirooka@gmail.com>, Chuck Vose <vosechu@gmail.com>
4
4
  #
5
5
  # This program is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU General Public License
@@ -31,9 +31,9 @@ class ErlangAdapter
31
31
 
32
32
  # Send commands to the Erlang server to be evaluated. Must have trailing
33
33
  # whitespace to differentiate between floats and EOL.
34
- def eval(command)
34
+ def eval(command)
35
35
  socket = TCPSocket.new(@host, @port)
36
-
36
+
37
37
  # There has to be a trailing space at the end of a command for erl_scan:tokens
38
38
  # to process the string.
39
39
  command << '.' if command.scan(/\.\w*/).empty?
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ require 'ruby-debug'
3
+ require 'rbridge'
4
+
5
+ class MnesiaAdapter
6
+ attr_reader :connection, :path
7
+
8
+ def initialize
9
+ @connection = RBridge.new(nil, 'localhost', 9900)
10
+
11
+ @connection.erl("mnesia:start().")
12
+ @connection.erl("mnesia:create_schema([node()]).")
13
+
14
+ debugger
15
+
16
+
17
+ @connection.erl("rr('tables.hrl').")
18
+
19
+ puts "here"
20
+ end
21
+ end
22
+
23
+ MnesiaAdapter.new
@@ -1,6 +1,6 @@
1
1
  # RBridge - A Ruby to Erlang bridge allowing the use of Erlang commands within
2
2
  # normal Ruby code.
3
- # Copyright (C) 2008 Toshiyuki Hirooka <toshi.hirooka@gmail.com>
3
+ # Copyright (C) 2008 Toshiyuki Hirooka <toshi.hirooka@gmail.com>, Chuck Vose <vosechu@gmail.com>
4
4
  #
5
5
  # This program is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU General Public License
@@ -17,13 +17,13 @@
17
17
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
18
 
19
19
  require "socket"
20
- require "lib/erlang_adapter"
20
+ require "erlang_adapter"
21
21
 
22
22
  #
23
23
  # Erlang サーバの関数を Ruby のメソッドのように扱えるようにするクラス
24
24
  #
25
25
  class RBridge
26
- VERSION = "0.1.2"
26
+ VERSION = "0.2.0"
27
27
 
28
28
  # [Mod]
29
29
  # Erlang module to use when using ruby-style access (the default is "erlang")
@@ -56,25 +56,46 @@ class RBridge
56
56
  erl(command, block)
57
57
  end
58
58
 
59
+ # def sql_erl(command, block=nil)
60
+ # res = command.scan(/[^\ ]+/)
61
+ # case res[0]
62
+ # when /select/i
63
+ # erl_command = "Q = qlc:q([X || X <- mnesia:table(#{res[3]})]),
64
+ # F = fun() -> qlc:e(Q) end,
65
+ # {atomic, Val} = mnesia:transaction(F),
66
+ # Val."
67
+ # else
68
+ # erl_command = nil
69
+ # end
70
+ #
71
+ # puts erl_command
72
+ # erl(erl_command, block)
73
+ # end
74
+
59
75
  # Send commands to Erlang to be processed.
60
- def erl(command, block=nil)
61
- begin
62
- if @async == true then
63
- # If we're asynchronous generate a thread around the call then pass
64
- # the results back to a block to display.
65
- Thread.new do
66
- res = @erlang.eval(command)
67
- raise res if @erlang.is_error(res)
68
- block.call(eval(res))
69
- end
70
- elsif @async == false then
71
- # Blocking mode should just eval and wait for data to come back.
72
- res = @erlang.eval(command)
73
- raise res if @erlang.is_error(res)
74
- eval res
75
- end
76
- rescue => res
77
- raise "[Error]=>#{res}"
78
- end
76
+ def erl(command, block=nil)
77
+ # log_p command
78
+ begin
79
+ if @async == true then
80
+ # If we're asynchronous generate a thread around the call then pass
81
+ # the results back to a block to display.
82
+ Thread.new do
83
+ res = @erlang.eval(command)
84
+ raise res if @erlang.is_error(res)
85
+ block.call(eval(res))
86
+ end
87
+ elsif @async == false then
88
+ # Blocking mode should just eval and wait for data to come back.
89
+ res = @erlang.eval(command)
90
+ raise res if @erlang.is_error(res)
91
+ eval res
92
+ end
93
+ rescue => res
94
+ raise "[Error]=>#{res}"
95
+ end
79
96
  end
97
+
98
+ # def tv
99
+ # erl("tv:start().")
100
+ # end
80
101
  end
@@ -1,8 +1,7 @@
1
- #!/usr/bin/env escript
2
1
  %% -*- erlang -*-
3
2
  % RBridge - A Ruby to Erlang bridge allowing the use of Erlang commands within
4
3
  % normal Ruby code.
5
- % Copyright (C) 2008 Toshiyuki Hirooka <toshi.hirooka@gmail.com>
4
+ % Copyright (C) 2008 Toshiyuki Hirooka <toshi.hirooka@gmail.com>, Chuck Vose <vosechu@gmail.com>
6
5
  %
7
6
  % This program is free software; you can redistribute it and/or
8
7
  % modify it under the terms of the GNU General Public License
@@ -17,19 +16,19 @@
17
16
  % You should have received a copy of the GNU General Public License
18
17
  % along with this program; if not, write to the Free Software
19
18
  % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
+ -module(rulang).
20
+ -export([start_server/1, stop_server/0, loop/1, handle_connection/1, main/1, usage/0]).
20
21
 
21
- -export([start_server/1, stop_server/0, loop/1, handle_connection/1]).
22
-
23
- main([String]) ->
22
+ main([Port]) ->
24
23
  try
25
- N = list_to_integer(String),
26
- start_server(N)
24
+ start_server(Port)
27
25
  catch
28
26
  _:_ ->
27
+ % TODO: This should report the error as well as the usage
29
28
  usage()
30
29
  end;
31
30
  main(_) ->
32
- start_server(9900).
31
+ usage().
33
32
 
34
33
  usage() ->
35
34
  io:format("./rulang [port number]").
@@ -40,7 +39,6 @@ start_server(Port) ->
40
39
  {ok, ListenSocket} = gen_tcp:listen(Port, [binary, {packet, 0}, {active, false}]),
41
40
  io:format("[RBridge Server Started]~n"),
42
41
  loop(ListenSocket).
43
-
44
42
 
45
43
  % Just kill the parent thread.
46
44
  stop_server() ->
@@ -54,26 +52,27 @@ loop(ListenSocket) ->
54
52
  case gen_tcp:accept(ListenSocket) of
55
53
 
56
54
  % If the connection is valid read the commands and attempt to eval them.
57
- {ok, Socket} ->
58
- spawn(fun() ->
59
- handle_connection(Socket)
55
+ {ok, Socket} ->
56
+ spawn(fun() ->
57
+ handle_connection(Socket)
60
58
  end),
61
- % Continue the loop
62
- loop(ListenSocket)
59
+
60
+ % Continue the loop
61
+ loop(ListenSocket)
63
62
  end.
64
63
 
65
64
  % Wrapper that catches errors and closes the socket after we're done with it.
66
65
  handle_connection(Socket) ->
67
- % Try to execute the commands in the tcp socket.
68
- try communication(Socket)
69
- % But catch any errors and pass them along to the tcp socket so we can see
66
+ % Try to execute the commands in the tcp socket.
67
+ try communication(Socket)
68
+ % But catch any errors and pass them along to the tcp socket so we can see
70
69
  % them in ruby.
71
70
  catch
72
71
  error:Reason ->
73
- {gen_tcp:send(Socket, io_lib:format("Error: ~p~n", [Reason]))}
72
+ {gen_tcp:send(Socket, io_lib:format("Error: ~p~n", [Reason]))}
74
73
  end,
75
74
  % Finally make sure the socket gets closed.
76
- ok = gen_tcp:close(Socket).
75
+ ok = gen_tcp:close(Socket).
77
76
 
78
77
  % Try to evaluate the code submitted throwing an exception if the evaluation
79
78
  % doesn't work.
metadata CHANGED
@@ -1,12 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbridge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ""
6
6
  authors:
7
7
  - Chuck Vose
8
8
  - Toshiyuki Hirooka
9
- - Sean Steiger-McRae
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain:
@@ -32,7 +31,7 @@ cert_chain:
32
31
  6uVjBw==
33
32
  -----END CERTIFICATE-----
34
33
 
35
- date: 2008-03-10 00:00:00 -07:00
34
+ date: 2008-05-24 00:00:00 -07:00
36
35
  default_executable:
37
36
  dependencies:
38
37
  - !ruby/object:Gem::Dependency
@@ -42,7 +41,7 @@ dependencies:
42
41
  requirements:
43
42
  - - ">="
44
43
  - !ruby/object:Gem::Version
45
- version: 1.4.0
44
+ version: 1.5.3
46
45
  version:
47
46
  description: "== DESCRIPTION: RBridge allows the use of Erlang code within a Ruby program. Optionally allowing asynchronous access and ruby-like syntax or by using Erlang code directly when more expressive or complex code is needed. == FEATURES/PROBLEMS: * Allows use of Erlang code within Ruby * Doesn't yet allow Ruby code within Erlang"
48
47
  email: vosechu@gmail.com
@@ -56,19 +55,20 @@ extra_rdoc_files:
56
55
  - History.txt
57
56
  - Manifest.txt
58
57
  - README.txt
58
+ - Todo.txt
59
59
  files:
60
- - .DS_Store
61
60
  - Authors.txt
62
61
  - GPL.txt
63
62
  - History.txt
64
63
  - Manifest.txt
65
64
  - README.txt
66
65
  - Rakefile
66
+ - Todo.txt
67
67
  - bin/rulang
68
68
  - lib/erlang_adapter.rb
69
+ - lib/mnesia_adapter.rb
69
70
  - lib/rbridge.rb
70
- - lib/vosetools.rb
71
- - rulang_server/rulang
71
+ - rulang_server/rulang.erl
72
72
  - spec/rulang_spec.rb
73
73
  - spec/spec_helper.rb
74
74
  has_rdoc: true
metadata.gz.sig CHANGED
Binary file
data/.DS_Store DELETED
Binary file
@@ -1,144 +0,0 @@
1
- # # These files may not be used in this project but are merely notes collected
2
- # # and inserted into all of Chuck Vose's projects. Please disregard them
3
- # # unless they help you.
4
-
5
- # # PLUGINS:
6
- # # Autotest with UnitRecord
7
- # # By default, running autotest in the Rails directory will run the unit tests.
8
- # # To run the functional tests, do: AUTOTEST='functional' autotest
9
- # ruby script/plugin install http://svn.soniciq.com/public/rails/plugins/iq_autotest
10
- # # Query Analyzer to see what we're doing under the surface
11
- # # Courtesy of Bob Silva at http://agilewebdevelopment.com/plugins/query_analyzer
12
- # ruby script/plugin install http://svn.nfectio.us/plugins/query_analyzer
13
- # # Dev mode performance cacher by Josh Goebel
14
- # # Caches dev code after file changes to make refreshes happen in the background
15
- # ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/dev_mode_performance_fixes/
16
- # # Rspec for running BDD
17
- # ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec
18
- # ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec_on_rails
19
-
20
- # # GEMS:
21
- # # UnitRecord disconnects tests from the database and restructures tests into
22
- # # Proper unit/functional tests. (Unit == no database, no externals). Run
23
- # # rake vose:convert_to_unitrecord[_and_commit] after installing.
24
- # sudo gem install unit_record
25
- # # Zentest provides test generation and autotest for hands free testing
26
- # # RSpec ~/.autotest file from http://reinh.com/2007/9/6/rspec-autotest-and-growl-oh-my
27
- # # Test::Unit ~/.autotest file from
28
- # sudo gem install zentest
29
- # # Dust provides some handy helper methods to testing
30
- # sudo gem install dust
31
- # # Mocha allows cross unit tests by mocking and stubbing functions
32
- # sudo gem install mocha
33
-
34
- require 'rubygems'
35
- # require 'mocha'
36
- # require 'stubba'
37
- # require 'dust'
38
-
39
- # require 'factory'
40
-
41
- module Vosetools
42
- def log_p(message)
43
- require 'pp'
44
-
45
- p "*********************"
46
- pp message
47
- p "*********************"
48
-
49
- # if !message.is_a?(Array)
50
- # `growlnotify -m "#{message}"`
51
- # end
52
- end
53
-
54
- def profile
55
- require 'ruby-prof'
56
-
57
- result = RubyProf.profile do
58
- yield
59
- end
60
-
61
- # Print a flat profile to text
62
- printer = RubyProf::FlatPrinter.new(result)
63
- printer.print(STDOUT, 5)
64
- end
65
-
66
- # def has_a(obj)
67
- # class_eval do
68
- # define_method(:method_missing) do |*values|
69
- # if obj.methods.include?(values[0])
70
- # log_p values
71
- # obj.send!(:values[0], values[1..(values.length-1)])
72
- # end
73
- # end
74
- # end
75
- # end
76
- end
77
-
78
- # # Adapted from http://sami.samhuri.net/2007/4/11/activerecord-base-find_or_create-and-find_or_initialize
79
- # # Originally created by sjs
80
- # module ActiveRecordExtensions
81
- # def self.included(base)
82
- # base.extend(ClassMethods)
83
- # end
84
- #
85
- # module ClassMethods
86
- # def find_or_create(params)
87
- # begin
88
- # return self.find(params[:id])
89
- # rescue ActiveRecord::RecordNotFound => e
90
- # attrs = {}
91
- #
92
- # # search for valid attributes in params
93
- # self.column_names.map(&:to_sym).each do |attrib|
94
- # # skip unknown columns, and the id field
95
- # next if params[attrib].nil? || attrib == :id
96
- #
97
- # attrs[attrib] = params[attrib]
98
- # end
99
- #
100
- # # call the appropriate ActiveRecord finder method
101
- # found = self.send("find_by_#{attrs.keys.join('_and_')}", *attrs.values) if !attrs.empty?
102
- #
103
- # if found && !found.nil?
104
- # return found
105
- # else
106
- # return self.create(params)
107
- # end
108
- # end
109
- # end
110
- # alias create_or_find find_or_create
111
- # end
112
- # end
113
- #
114
- # ActiveRecord::Base.send(:include, ActiveRecordExtensions)
115
-
116
- # Copyright: Jay Philips
117
- # jicksta.com/articles/2007/08/04/the-methodphitamine
118
- module Kernel
119
- protected
120
- def it() It.new end
121
- alias its it
122
- end
123
-
124
- class It
125
-
126
- undef_method(*(instance_methods - %w*__id__ __send__*))
127
-
128
- def initialize
129
- @methods = []
130
- end
131
-
132
- def method_missing(*args, &block)
133
- @methods << [args, block] unless args == [:respond_to?, :to_proc]
134
- self
135
- end
136
-
137
- def to_proc
138
- lambda do |obj|
139
- @methods.inject(obj) do |current,(args,block)|
140
- current.send(*args, &block)
141
- end
142
- end
143
- end
144
- end