emdrb 0.3.1 → 0.4.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/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.4.0 / 2009-03-18
2
+ * Mechanism for deferrable methods using blocks cleaned up further
3
+ * Asynchronous method call API cleaned up
4
+
5
+ == 0.3.2 / 2009-03-16
6
+ * Deferrable method mechanism cleaned up
7
+
1
8
  == 0.3.1 / 2009-02-04
2
9
  * Used EventMachine::defer instead of spawning own threads
3
10
 
data/README.txt CHANGED
@@ -97,11 +97,6 @@ Or it could be written to use of asynchronous calls:
97
97
 
98
98
  * Standard gem installation: 'sudo gem install' ought to do the trick.
99
99
 
100
- Note that you will need the daemons gem ('sudo gem install daemons')
101
- if you would like to run the rspec tests that are included with
102
- EMDRb. Daemons is not required to use EMDRb otherwise, and as such it
103
- is not listed as a hard dependency in the gem install.
104
-
105
100
  If you want to install it manually, you can always download it at the
106
101
  EMDRb project page at:
107
102
 
@@ -113,5 +108,5 @@ Copyright © 2008, 2009 Rafael R. Sevilla. You can redistribute it
113
108
  and/or modify it under the same terms as Ruby. Please see the file
114
109
  COPYING for more details.
115
110
 
116
- $Id: README.txt 88 2009-02-04 04:10:52Z dido $
111
+ $Id: README.txt 104 2009-03-18 04:45:56Z dido $
117
112
 
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
- # -*- Ruby -*-
1
+ # -*- coding: utf-8; mode: Ruby -*-
2
2
  #
3
3
  # Author:: Rafael R. Sevilla (mailto:dido@imperium.ph)
4
4
  # Copyright:: Copyright © 2008, 2009 Rafael R. Sevilla
5
5
  # Homepage:: http://emdrb.rubyforge.org/
6
6
  # License:: GNU General Public License / Ruby License
7
7
  #
8
- # $Id: Rakefile 61 2009-01-23 09:11:43Z dido $
8
+ # $Id: Rakefile 94 2009-03-14 07:17:37Z dido $
9
9
  #
10
10
  #----------------------------------------------------------------------------
11
11
  #
@@ -20,7 +20,16 @@
20
20
  # See the file COPYING for complete licensing information.
21
21
  #----------------------------------------------------------------------------
22
22
  #
23
- load 'tasks/setup.rb'
23
+ begin
24
+ require 'bones'
25
+ Bones.setup
26
+ rescue LoadError
27
+ begin
28
+ load 'tasks/setup.rb'
29
+ rescue LoadError
30
+ raise RuntimeError, '### please install the "bones" gem ###'
31
+ end
32
+ end
24
33
 
25
34
  ensure_in_path 'lib'
26
35
  require 'emdrb/version'
@@ -32,8 +41,8 @@ PROJ.authors = 'dido@imperium.ph'
32
41
  PROJ.email = 'dido@imperium.ph'
33
42
  PROJ.url = 'http://emdrb.rubyforge.org'
34
43
  PROJ.rubyforge.name = 'emdrb'
35
- PROJ.version = EMDRb::Version::STRING
36
- PROJ.dependencies = ["eventmachine"]
44
+ PROJ.version = EMDRb::VERSION
45
+ depend_on "eventmachine"
37
46
 
38
47
  PROJ.spec.opts << '--color'
39
48
 
data/lib/emdrb/emdrb.rb CHANGED
@@ -1,10 +1,11 @@
1
+ # -*- coding: utf-8 -*-
1
2
  #
2
3
  # Author:: Rafael R. Sevilla (mailto:dido@imperium.ph)
3
4
  # Copyright:: Copyright © 2008, 2009 Rafael R. Sevilla
4
5
  # Homepage:: http://emdrb.rubyforge.org/
5
6
  # License:: GNU General Public License / Ruby License
6
7
  #
7
- # $Id: emdrb.rb 87 2009-02-04 04:08:06Z dido $
8
+ # $Id: emdrb.rb 107 2009-03-18 05:52:00Z dido $
8
9
  #
9
10
  #----------------------------------------------------------------------------
10
11
  #
@@ -37,20 +38,27 @@ module DRb
37
38
  # most especially with respect to blocks. This may also provide more
38
39
  # performance if one is using a method that itself makes use of
39
40
  # Deferrables to accomplish the job.
41
+ #
42
+ # There are certain rules that deferrable methods must obey:
43
+ #
44
+ # 1. They must always return a Deferrable to their caller. This
45
+ # Deferrable should succeed if the method returns a normal value,
46
+ # passing its result as a parameter to any of its callbacks.
47
+ # 2. Exceptions must be caught and the Deferrable they return must
48
+ # fail, with the exception object passed as a parameter to its
49
+ # errbacks.
50
+ # 3. Blocks passed to the deferrable method will always return a
51
+ # Deferrable, which again will succeed
52
+ #
40
53
  #
41
54
  module DRbEMSafe
42
55
  module ClassMethods
43
56
  ##
44
- # Mark the method as a deferrable method. Such a method must
45
- # accept two arguments, an array of parameters and a block
46
- # (usually nil). The method must always return a Deferrable
47
- # which should be set to success with the result of the method
48
- # when the method is done, and failed with the exception object
49
- # if the method failed. The block, if any, is a DRbObject that
50
- # should be invoked by send_async(:call). Using a direct call
51
- # on the DRbObject will most likely result in a threading
52
- # deadlock since deferrable methods are invoked from the main
53
- # thread!
57
+ # Mark the method as a deferrable method. Such a method must always
58
+ # return an object which includes EventMachine::Deferrable. A block
59
+ # passed to such a method returns a deferrable whenever it is invoked,
60
+ # by doing a direct call to the block or using yield, and the code
61
+ # for the deferrable method must take this into account.
54
62
  def deferrable_method(method_name)
55
63
  @deferrable_methods ||= {}
56
64
  @deferrable_methods[method_name] = true
@@ -59,6 +67,7 @@ module DRb
59
67
  def deferrable_method?(method_name)
60
68
  return(@deferrable_methods.has_key?(method_name))
61
69
  end
70
+
62
71
  end
63
72
 
64
73
  def self.included(base)
@@ -66,6 +75,37 @@ module DRb
66
75
  end
67
76
  end
68
77
 
78
+ ##
79
+ # Used to wrap Proc objects so that they can be safely called from
80
+ # deferrable methods. This makes any invocation of the block an
81
+ # asynchronous call that returns a Deferrable rather than calling
82
+ # the block synchronously, which will result in a threading deadlock
83
+ # if this is performed in the main event loop. This mechanism is
84
+ # used to provide facilities for deferrable methods which run within
85
+ # the master event loop.
86
+ class DRbProcWrapper
87
+ def initialize(block)
88
+ @block = block
89
+ end
90
+
91
+ ##
92
+ # Initiate an asynchronous call to the block this is wrapping around.
93
+ # Returns a deferrable.
94
+ def call(*args)
95
+ if args.size == 1 && args[0].class == Array
96
+ args[0] = DRbArray.new(args[0])
97
+ end
98
+ return(@block.send_async(:call, *args))
99
+ end
100
+
101
+ ##
102
+ # Return a Proc that will do an asynchronous call to the underlying
103
+ # object.
104
+ def to_proc
105
+ return(Proc.new { |args| self.call(args) })
106
+ end
107
+ end
108
+
69
109
  ##
70
110
  # Common protocol elements for distributed Ruby, used by both the
71
111
  # client and server.
@@ -300,9 +340,15 @@ module DRb
300
340
  @request[:ro].class.deferrable_method?(@request[:msg])
301
341
  # A deferrable method will return an actual Deferrable that we
302
342
  # can use instead.
303
- return(@request[:ro].__send__(@request[:msg],
304
- @request[:argv],
305
- @request[:block]))
343
+ begin
344
+ return(@request[:ro].__send__(@request[:msg],
345
+ *@request[:argv],
346
+ &DRbProcWrapper.new(@request[:block])))
347
+ rescue
348
+ df = EventMachine::DefaultDeferrable.new
349
+ df.fail($!)
350
+ return(df)
351
+ end
306
352
  end
307
353
  df = EventMachine::DefaultDeferrable.new
308
354
  op = (@request[:block]) ? perform_with_block : perform_without_block
@@ -745,8 +791,7 @@ module DRb
745
791
  else
746
792
  @result = obj
747
793
  @state = :succ
748
- @df.set_deferred_status(:succeeded, [@succ, @result])
749
- # close the connection after the call succeeds.
794
+ @succ ? @df.succeed(@result) : @df.fail(@result)
750
795
  close_connection
751
796
  end
752
797
  end
@@ -777,10 +822,25 @@ module DRb
777
822
 
778
823
  ##
779
824
  # Perform an asynchronous call to the remote object. This can only
780
- # be used from within the event loop. It returns a deferrable to which
781
- # callbacks can be attached.
825
+ # be used from within the event loop. It returns a deferrable, which
826
+ # will succeed if the remote method called performs a normal return,
827
+ # and callbacks attached to the deferrable will receive this return
828
+ # value. If the remote method raises an exception, it will fail the
829
+ # deferrable, and the exception object will be passed to the errbacks
830
+ # of the deferrable.
782
831
  def send_async(msg_id, *a, &b)
783
832
  df = EventMachine::DefaultDeferrable.new
833
+ if DRb.here?(@uri)
834
+ obj = DRb.to_obj(@ref)
835
+ DRb.current_server.check_insecure_method(obj, msg_id)
836
+ begin
837
+ df.succeed(obj.__send__(msg_id, *a, &b))
838
+ rescue
839
+ df.fail($!)
840
+ end
841
+ return(df)
842
+ end
843
+
784
844
  @protocol ||= DRbTransport.factory(@uri, DRb.config)
785
845
 
786
846
  @protocol.client_connect(DRbClientProtocol) do |c|
@@ -801,16 +861,11 @@ module DRb
801
861
  # threading deadlock! Use the send_async method if you want to
802
862
  # use EMDRb from within an event loop.
803
863
  def method_missing(msg_id, *a, &b)
804
- if DRb.here?(@uri)
805
- obj = DRb.to_obj(@ref)
806
- DRb.current_server.check_insecure_method(obj, msg_id)
807
- return obj.__send__(msg_id, *a, &b)
808
- end
809
-
810
864
  q = Queue.new
811
865
  EventMachine::next_tick do
812
866
  df = self.send_async(msg_id, *a, &b)
813
- df.callback { |data| q << data }
867
+ df.callback { |data| q << [true, data] }
868
+ df.errback { |exc| q << [false, exc] }
814
869
  end
815
870
  succ, result = q.shift
816
871
  if succ
data/lib/emdrb/version.rb CHANGED
@@ -4,7 +4,7 @@
4
4
  # Homepage:: http://emdrb.rubyforge.org/
5
5
  # License:: GNU Lesser General Public License / Ruby License
6
6
  #
7
- # $Id: version.rb 83 2009-02-04 03:39:51Z dido $
7
+ # $Id: version.rb 110 2009-03-18 05:55:43Z dido $
8
8
  #
9
9
  #----------------------------------------------------------------------------
10
10
  #
@@ -22,13 +22,5 @@
22
22
  # EMDRb version code
23
23
  #
24
24
  module EMDRb
25
- module Version
26
-
27
- MAJOR = 0
28
- MINOR = 3
29
- TINY = 1
30
-
31
- # The version of EMDRb in use.
32
- STRING = [ MAJOR, MINOR, TINY ].join(".")
33
- end
25
+ VERSION = "0.4.0"
34
26
  end
data/spec/client_spec.rb CHANGED
@@ -1,10 +1,11 @@
1
+ # -*- coding: utf-8 -*-
1
2
  #
2
3
  # Author:: Rafael R. Sevilla (mailto:dido@imperium.ph)
3
4
  # Copyright:: Copyright © 2008, 2009 Rafael R. Sevilla
4
5
  # Homepage:: http://emdrb.rubyforge.org/
5
6
  # License:: GNU General Public License / Ruby License
6
7
  #
7
- # $Id: client_spec.rb 50 2009-01-23 08:52:21Z dido $
8
+ # $Id: client_spec.rb 105 2009-03-18 05:48:08Z dido $
8
9
  #
9
10
  #----------------------------------------------------------------------------
10
11
  #
@@ -21,41 +22,45 @@
21
22
  #
22
23
  require File.join(File.dirname(__FILE__), %w[spec_helper])
23
24
  require File.join(File.dirname(__FILE__), %w[spec_common])
25
+ require 'thread'
24
26
 
25
27
  Thread.abort_on_exception = true
26
28
 
27
29
  describe EMDRb, "Client" do
28
30
  it_should_behave_like "DRb basics"
29
31
 
30
- before(:all) do
31
- system(File.join(File.dirname(__FILE__), "drbserver.rb drb"))
32
+ before do
32
33
  DRb.start_service
33
34
  @obj = DRb::DRbObject.new(nil, "druby://localhost:12345")
34
35
  end
35
36
 
36
- after(:all) do
37
- pid = File.open(File.join(File.dirname(__FILE__), "drbserver.pid")) { |fp| fp.read.to_i }
38
- Process.kill("SIGTERM", pid)
37
+ after do
38
+ DRb.stop_service
39
39
  end
40
40
 
41
41
  it "should be able to perform asynchronous method calls" do
42
+ q = Queue.new
42
43
  EventMachine::next_tick do
43
44
  @obj.send_async(:identity, 1).callback do |data|
44
- data[0].should be_true
45
- data[1].should == 1
45
+ q << data
46
46
  end
47
47
  end
48
+ data = q.shift
49
+ data.should == 1
48
50
  end
49
51
 
50
52
  it "should be able to perform asynchronous method calls with a passed block" do
53
+ q = Queue.new
54
+ val = 1
51
55
  EventMachine::next_tick do
52
- val = 1
53
56
  df = @obj.send_async(:blockyield, 1,2,3,4,5,6,7) { |x| val *= x; val }
54
57
  df.callback do |data|
55
- data[0].should be_true
56
- val.should == 5040
58
+ q << data
57
59
  end
58
60
  end
61
+ data = q.shift
62
+ data[0].should be_true
63
+ val.should == 5040
59
64
  end
60
65
 
61
66
  end
data/spec/drbserver.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
2
3
  # Author:: Rafael R. Sevilla (mailto:dido@imperium.ph)
3
4
  # Copyright:: Copyright © 2008, 2009 Rafael R. Sevilla
4
5
  # Homepage:: http://emdrb.rubyforge.org/
5
6
  # License:: GNU General Public License / Ruby License
6
7
  #
7
- # $Id: drbserver.rb 66 2009-01-27 07:25:23Z dido $
8
+ # $Id: drbserver.rb 106 2009-03-18 05:48:53Z dido $
8
9
  #
9
10
  #----------------------------------------------------------------------------
10
11
  #
@@ -22,7 +23,7 @@
22
23
  # This is the DRb server that should be run by the specs, and can execute
23
24
  # using either the standard DRb or EMDRb depending on what is being tested.
24
25
  #
25
- require 'daemons'
26
+
26
27
  Thread.abort_on_exception = true
27
28
  if ARGV[0] == "emdrb"
28
29
  $LOAD_PATH << File.join(File.dirname(__FILE__), '../lib/')
@@ -33,25 +34,6 @@ else
33
34
  raise "specify emdrb or drb on the command line"
34
35
  end
35
36
 
36
- if ARGV[1].nil?
37
- pidfile = File.expand_path(File.join(File.dirname(__FILE__), "drbserver.pid"))
38
- if File.exist?(pidfile)
39
- exit(0)
40
- end
41
- # logfile = File.expand_path(File.join(File.dirname(__FILE__), "drbserver.log"))
42
- Daemonize.daemonize
43
- pid = Process.pid
44
- File.open(pidfile, "w") { |fp| fp.write(pid.to_s) }
45
-
46
- handler = lambda do
47
- File.delete(pidfile)
48
- exit(0)
49
- end
50
-
51
- trap("SIGTERM", handler)
52
- trap("SIGINT", handler)
53
- end
54
-
55
37
  class TestServer
56
38
  def identity(x)
57
39
  return(x)
@@ -82,25 +64,20 @@ if ARGV[0] == "emdrb"
82
64
  ##
83
65
  # Simple example of a deferrable method structured as a state
84
66
  # machine.
85
- def block_df(args, block, state={:index => 0, :retval => 0 })
86
- if state[:index] >= args.length
67
+ def block_df(data, state={:index => 0, :retval => 0 }, &block)
68
+ if state[:index] >= data.length
87
69
  self.set_deferred_status(:succeeded, state[:retval])
88
70
  return(self)
89
71
  end
90
72
 
91
- df = block.send_async(:call, args[state[:index]])
92
- df.callback do |succ,result|
93
- if succ
94
- state[:retval] += result
95
- state[:index] += 1
96
- EventMachine::next_tick do
97
- self.block_df(args, block, state)
98
- end
99
- else
100
- self.set_deferred_status(:failed, res)
101
- end
73
+ df = yield data[state[:index]]
74
+ df.callback do |result|
75
+ state[:retval] += result
76
+ state[:index] += 1
77
+ self.block_df(data, state, &block)
102
78
  end
103
79
  df.errback do |res|
80
+ df.fail(res)
104
81
  end
105
82
  return(self)
106
83
  end
data/spec/server_spec.rb CHANGED
@@ -1,10 +1,11 @@
1
+ # -*- coding: utf-8 -*-
1
2
  #
2
3
  # Author:: Rafael R. Sevilla (mailto:dido@imperium.ph)
3
4
  # Copyright:: Copyright © 2008, 2009 Rafael R. Sevilla
4
5
  # Homepage:: http://emdrb.rubyforge.org/
5
6
  # License:: GNU General Public License / Ruby License
6
7
  #
7
- # $Id: server_spec.rb 65 2009-01-27 07:24:53Z dido $
8
+ # $Id: server_spec.rb 108 2009-03-18 05:53:00Z dido $
8
9
  #
9
10
  #----------------------------------------------------------------------------
10
11
  #
@@ -33,15 +34,12 @@ describe "EMDRb Server" do
33
34
  it_should_behave_like "DRb basics"
34
35
 
35
36
  before(:all) do
36
- # but we start the *server* with EMDRb
37
- system(File.join(File.dirname(__FILE__), "drbserver.rb emdrb"))
38
37
  DRb.start_service
39
38
  @obj = DRbObject.new_with_uri("druby://localhost:12345")
40
39
  end
41
40
 
42
41
  after(:all) do
43
- pid = File.open(File.join(File.dirname(__FILE__), "drbserver.pid")) { |fp| fp.read.to_i }
44
- Process.kill("SIGTERM", pid)
42
+ DRb.stop_service
45
43
  end
46
44
 
47
45
  it "should work with variadic methods" do
@@ -49,7 +47,7 @@ describe "EMDRb Server" do
49
47
  end
50
48
 
51
49
  it "should use deferrable methods correctly" do
52
- res = @obj.block_df(1,2,3,4,5) { |x| x }
50
+ res = @obj.block_df([1,2,3,4,5]) { |x| x }
53
51
  res.should == 15
54
52
  end
55
53
 
data/tasks/ann.rake CHANGED
@@ -1,4 +1,3 @@
1
- # $Id: ann.rake 59 2009-01-23 09:10:01Z dido $
2
1
 
3
2
  begin
4
3
  require 'bones/smtp_tls'
@@ -43,7 +42,7 @@ namespace :ann do
43
42
  desc "Send an email announcement"
44
43
  task :email => ['ann:prereqs', PROJ.ann.file] do
45
44
  ann = PROJ.ann
46
- from = ann.email[:from] || PROJ.email
45
+ from = ann.email[:from] || Array(PROJ.authors).first || PROJ.email
47
46
  to = Array(ann.email[:to])
48
47
 
49
48
  ### build a mail header for RFC 822
data/tasks/bones.rake CHANGED
@@ -1,4 +1,3 @@
1
- # $Id: bones.rake 59 2009-01-23 09:10:01Z dido $
2
1
 
3
2
  if HAVE_BONES
4
3
 
data/tasks/gem.rake CHANGED
@@ -1,6 +1,94 @@
1
- # $Id: gem.rake 59 2009-01-23 09:10:01Z dido $
2
1
 
3
- require 'rake/gempackagetask'
2
+ require 'find'
3
+ require 'rake/packagetask'
4
+ require 'rubygems/user_interaction'
5
+ require 'rubygems/builder'
6
+
7
+ module Bones
8
+ class GemPackageTask < Rake::PackageTask
9
+ # Ruby GEM spec containing the metadata for this package. The
10
+ # name, version and package_files are automatically determined
11
+ # from the GEM spec and don't need to be explicitly provided.
12
+ #
13
+ attr_accessor :gem_spec
14
+
15
+ # Tasks from the Bones gem directory
16
+ attr_reader :bones_files
17
+
18
+ # Create a GEM Package task library. Automatically define the gem
19
+ # if a block is given. If no block is supplied, then +define+
20
+ # needs to be called to define the task.
21
+ #
22
+ def initialize(gem_spec)
23
+ init(gem_spec)
24
+ yield self if block_given?
25
+ define if block_given?
26
+ end
27
+
28
+ # Initialization tasks without the "yield self" or define
29
+ # operations.
30
+ #
31
+ def init(gem)
32
+ super(gem.name, gem.version)
33
+ @gem_spec = gem
34
+ @package_files += gem_spec.files if gem_spec.files
35
+ @bones_files = []
36
+
37
+ local_setup = File.join(Dir.pwd, %w[tasks setup.rb])
38
+ if !test(?e, local_setup)
39
+ Dir.glob(::Bones.path(%w[lib bones tasks *])).each {|fn| bones_files << fn}
40
+ end
41
+ end
42
+
43
+ # Create the Rake tasks and actions specified by this
44
+ # GemPackageTask. (+define+ is automatically called if a block is
45
+ # given to +new+).
46
+ #
47
+ def define
48
+ super
49
+ task :prereqs
50
+ task :package => ['gem:prereqs', "#{package_dir_path}/#{gem_file}"]
51
+ file "#{package_dir_path}/#{gem_file}" => [package_dir_path] + package_files + bones_files do
52
+ when_writing("Creating GEM") {
53
+ chdir(package_dir_path) do
54
+ Gem::Builder.new(gem_spec).build
55
+ verbose(true) {
56
+ mv gem_file, "../#{gem_file}"
57
+ }
58
+ end
59
+ }
60
+ end
61
+
62
+ file package_dir_path => bones_files do
63
+ mkdir_p package_dir rescue nil
64
+
65
+ gem_spec.files = (gem_spec.files +
66
+ bones_files.map {|fn| File.join('tasks', File.basename(fn))}).sort
67
+
68
+ bones_files.each do |fn|
69
+ base_fn = File.join('tasks', File.basename(fn))
70
+ f = File.join(package_dir_path, base_fn)
71
+ fdir = File.dirname(f)
72
+ mkdir_p(fdir) if !File.exist?(fdir)
73
+ if File.directory?(fn)
74
+ mkdir_p(f)
75
+ else
76
+ raise "file name conflict for '#{base_fn}' (conflicts with '#{fn}')" if test(?e, f)
77
+ safe_ln(fn, f)
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ def gem_file
84
+ if @gem_spec.platform == Gem::Platform::RUBY
85
+ "#{package_name}.gem"
86
+ else
87
+ "#{package_name}-#{@gem_spec.platform}.gem"
88
+ end
89
+ end
90
+ end # class GemPackageTask
91
+ end # module Bones
4
92
 
5
93
  namespace :gem do
6
94
 
@@ -19,6 +107,10 @@ namespace :gem do
19
107
  s.add_dependency(*dep)
20
108
  end
21
109
 
110
+ PROJ.gem.development_dependencies.each do |dep|
111
+ s.add_development_dependency(*dep)
112
+ end
113
+
22
114
  s.files = PROJ.gem.files
23
115
  s.executables = PROJ.gem.executables.map {|fn| File.basename(fn)}
24
116
  s.extensions = PROJ.gem.files.grep %r/extconf\.rb$/
@@ -57,37 +149,21 @@ namespace :gem do
57
149
  end
58
150
  end # Gem::Specification.new
59
151
 
60
- # A prerequisites task that all other tasks depend upon
61
- task :prereqs
152
+ Bones::GemPackageTask.new(PROJ.gem._spec) do |pkg|
153
+ pkg.need_tar = PROJ.gem.need_tar
154
+ pkg.need_zip = PROJ.gem.need_zip
155
+ end
62
156
 
63
157
  desc 'Show information about the gem'
64
158
  task :debug => 'gem:prereqs' do
65
159
  puts PROJ.gem._spec.to_ruby
66
160
  end
67
161
 
68
- pkg = Rake::PackageTask.new(PROJ.name, PROJ.version) do |pkg|
69
- pkg.need_tar = PROJ.gem.need_tar
70
- pkg.need_zip = PROJ.gem.need_zip
71
- pkg.package_files += PROJ.gem._spec.files
72
- end
73
- Rake::Task['gem:package'].instance_variable_set(:@full_comment, nil)
74
-
75
- gem_file = if PROJ.gem._spec.platform == Gem::Platform::RUBY
76
- "#{pkg.package_name}.gem"
77
- else
78
- "#{pkg.package_name}-#{PROJ.gem._spec.platform}.gem"
162
+ desc 'Write the gemspec '
163
+ task :spec => 'gem:prereqs' do
164
+ File.open("#{PROJ.name}.gemspec", 'w') do |f|
165
+ f.write PROJ.gem._spec.to_ruby
79
166
  end
80
-
81
- desc "Build the gem file #{gem_file}"
82
- task :package => ['gem:prereqs', "#{pkg.package_dir}/#{gem_file}"]
83
-
84
- file "#{pkg.package_dir}/#{gem_file}" => [pkg.package_dir] + PROJ.gem._spec.files do
85
- when_writing("Creating GEM") {
86
- Gem::Builder.new(PROJ.gem._spec).build
87
- verbose(true) {
88
- mv gem_file, "#{pkg.package_dir}/#{gem_file}"
89
- }
90
- }
91
167
  end
92
168
 
93
169
  desc 'Install the gem'
@@ -113,14 +189,13 @@ namespace :gem do
113
189
  task :cleanup do
114
190
  sh "#{SUDO} #{GEM} cleanup #{PROJ.gem._spec.name}"
115
191
  end
116
-
117
192
  end # namespace :gem
118
193
 
194
+
119
195
  desc 'Alias to gem:package'
120
196
  task :gem => 'gem:package'
121
197
 
122
198
  task :clobber => 'gem:clobber_package'
123
-
124
- remove_desc_for_task %w(gem:clobber_package)
199
+ remove_desc_for_task 'gem:clobber_package'
125
200
 
126
201
  # EOF
data/tasks/git.rake CHANGED
@@ -1,4 +1,3 @@
1
- # $Id: git.rake 59 2009-01-23 09:10:01Z dido $
2
1
 
3
2
  if HAVE_GIT
4
3
 
data/tasks/notes.rake CHANGED
@@ -1,4 +1,3 @@
1
- # $Id: notes.rake 59 2009-01-23 09:10:01Z dido $
2
1
 
3
2
  if HAVE_BONES
4
3
 
data/tasks/post_load.rake CHANGED
@@ -1,16 +1,16 @@
1
- # $Id: post_load.rake 59 2009-01-23 09:10:01Z dido $
2
1
 
3
2
  # This file does not define any rake tasks. It is used to load some project
4
3
  # settings if they are not defined by the user.
5
4
 
6
- PROJ.rdoc.exclude << "^#{Regexp.escape(PROJ.manifest_file)}$"
7
5
  PROJ.exclude << ["^#{Regexp.escape(PROJ.ann.file)}$",
6
+ "^#{Regexp.escape(PROJ.ignore_file)}$",
8
7
  "^#{Regexp.escape(PROJ.rdoc.dir)}/",
9
8
  "^#{Regexp.escape(PROJ.rcov.dir)}/"]
10
9
 
11
10
  flatten_arrays = lambda do |this,os|
12
11
  os.instance_variable_get(:@table).each do |key,val|
13
- next if key == :dependencies
12
+ next if key == :dependencies \
13
+ or key == :development_dependencies
14
14
  case val
15
15
  when Array; val.flatten!
16
16
  when OpenStruct; this.call(this,val)
@@ -25,12 +25,7 @@ PROJ.description ||= paragraphs_of(PROJ.readme_file, 'description').join("\n\n")
25
25
 
26
26
  PROJ.summary ||= PROJ.description.split('.').first
27
27
 
28
- PROJ.gem.files ||=
29
- if test(?f, PROJ.manifest_file)
30
- files = File.readlines(PROJ.manifest_file).map {|fn| fn.chomp.strip}
31
- files.delete ''
32
- files
33
- else [] end
28
+ PROJ.gem.files ||= manifest
34
29
 
35
30
  PROJ.gem.executables ||= PROJ.gem.files.find_all {|fn| fn =~ %r/^bin/}
36
31
 
data/tasks/rdoc.rake CHANGED
@@ -1,4 +1,3 @@
1
- # $Id: rdoc.rake 59 2009-01-23 09:10:01Z dido $
2
1
 
3
2
  require 'rake/rdoctask'
4
3
 
@@ -20,10 +19,11 @@ namespace :doc do
20
19
  end
21
20
  rd.rdoc_files.push(*files)
22
21
 
23
- title = "#{PROJ.name}-#{PROJ.version} Documentation"
24
-
22
+ name = PROJ.name
25
23
  rf_name = PROJ.rubyforge.name
26
- title = "#{rf_name}'s " + title if rf_name.valid? and rf_name != title
24
+
25
+ title = "#{name}-#{PROJ.version} Documentation"
26
+ title = "#{rf_name}'s " + title if rf_name.valid? and rf_name != name
27
27
 
28
28
  rd.options << "-t #{title}"
29
29
  rd.options.concat(rdoc.opts)
data/tasks/rubyforge.rake CHANGED
@@ -6,7 +6,7 @@ require 'rake/contrib/sshpublisher'
6
6
 
7
7
  namespace :gem do
8
8
  desc 'Package and upload to RubyForge'
9
- task :release => [:clobber, 'gem:package'] do |t|
9
+ task :release => [:clobber, 'gem'] do |t|
10
10
  v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
11
11
  abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
12
12
  pkg = "pkg/#{PROJ.gem._spec.full_name}"
@@ -26,9 +26,7 @@ namespace :gem do
26
26
  c['release_changes'] = PROJ.changes if PROJ.changes
27
27
  c['preformatted'] = true
28
28
 
29
- files = [(PROJ.gem.need_tar ? "#{pkg}.tgz" : nil),
30
- (PROJ.gem.need_zip ? "#{pkg}.zip" : nil),
31
- "#{pkg}.gem"].compact
29
+ files = Dir.glob("#{pkg}*.*")
32
30
 
33
31
  puts "Releasing #{PROJ.name} v. #{PROJ.version}"
34
32
  rf.add_release PROJ.rubyforge.name, PROJ.name, PROJ.version, *files
data/tasks/setup.rb CHANGED
@@ -1,12 +1,15 @@
1
- # $Id: setup.rb 59 2009-01-23 09:10:01Z dido $
2
1
 
3
2
  require 'rubygems'
4
3
  require 'rake'
5
4
  require 'rake/clean'
6
5
  require 'fileutils'
7
6
  require 'ostruct'
7
+ require 'find'
8
8
 
9
- class OpenStruct; undef :gem; end
9
+ class OpenStruct; undef :gem if defined? :gem; end
10
+
11
+ # TODO: make my own openstruct type object that includes descriptions
12
+ # TODO: use the descriptions to output help on the available bones options
10
13
 
11
14
  PROJ = OpenStruct.new(
12
15
  # Project Defaults
@@ -25,8 +28,8 @@ PROJ = OpenStruct.new(
25
28
  :ruby_opts => %w(-w),
26
29
  :libs => [],
27
30
  :history_file => 'History.txt',
28
- :manifest_file => 'Manifest.txt',
29
31
  :readme_file => 'README.txt',
32
+ :ignore_file => '.bnsignore',
30
33
 
31
34
  # Announce
32
35
  :ann => OpenStruct.new(
@@ -48,6 +51,7 @@ PROJ = OpenStruct.new(
48
51
  # Gem Packaging
49
52
  :gem => OpenStruct.new(
50
53
  :dependencies => [],
54
+ :development_dependencies => [],
51
55
  :executables => nil,
52
56
  :extensions => FileList['ext/**/extconf.rb'],
53
57
  :files => nil,
@@ -59,7 +63,7 @@ PROJ = OpenStruct.new(
59
63
  # File Annotations
60
64
  :notes => OpenStruct.new(
61
65
  :exclude => %w(^tasks/setup\.rb$),
62
- :extensions => %w(.txt .rb .erb) << '',
66
+ :extensions => %w(.txt .rb .erb .rdoc) << '',
63
67
  :tags => %w(FIXME OPTIMIZE TODO)
64
68
  ),
65
69
 
@@ -74,7 +78,7 @@ PROJ = OpenStruct.new(
74
78
  # Rdoc
75
79
  :rdoc => OpenStruct.new(
76
80
  :opts => [],
77
- :include => %w(^lib/ ^bin/ ^ext/ \.txt$),
81
+ :include => %w(^lib/ ^bin/ ^ext/ \.txt$ \.rdoc$),
78
82
  :exclude => %w(extconf\.rb$),
79
83
  :main => nil,
80
84
  :dir => 'doc',
@@ -110,17 +114,17 @@ PROJ = OpenStruct.new(
110
114
  )
111
115
 
112
116
  # Load the other rake files in the tasks folder
113
- rakefiles = Dir.glob('tasks/*.rake').sort
114
- rakefiles.unshift(rakefiles.delete('tasks/post_load.rake')).compact!
117
+ tasks_dir = File.expand_path(File.dirname(__FILE__))
118
+ post_load_fn = File.join(tasks_dir, 'post_load.rake')
119
+ rakefiles = Dir.glob(File.join(tasks_dir, '*.rake')).sort
120
+ rakefiles.unshift(rakefiles.delete(post_load_fn)).compact!
115
121
  import(*rakefiles)
116
122
 
117
123
  # Setup the project libraries
118
124
  %w(lib ext).each {|dir| PROJ.libs << dir if test ?d, dir}
119
125
 
120
126
  # Setup some constants
121
- WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WIN32
122
-
123
- DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
127
+ DEV_NULL = File.exist?('/dev/null') ? '/dev/null' : 'NUL:'
124
128
 
125
129
  def quiet( &block )
126
130
  io = [STDOUT.dup, STDERR.dup]
@@ -133,21 +137,15 @@ ensure
133
137
  $stdout, $stderr = STDOUT, STDERR
134
138
  end
135
139
 
136
- DIFF = if WIN32 then 'diff.exe'
137
- else
138
- if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
139
- else 'diff' end
140
- end unless defined? DIFF
140
+ DIFF = if system("gdiff '#{__FILE__}' '#{__FILE__}' > #{DEV_NULL} 2>&1") then 'gdiff'
141
+ else 'diff' end unless defined? DIFF
141
142
 
142
- SUDO = if WIN32 then ''
143
- else
144
- if quiet {system 'which sudo'} then 'sudo'
145
- else '' end
146
- end
143
+ SUDO = if system("which sudo > #{DEV_NULL} 2>&1") then 'sudo'
144
+ else '' end unless defined? SUDO
147
145
 
148
- RCOV = WIN32 ? 'rcov.bat' : 'rcov'
149
- RDOC = WIN32 ? 'rdoc.bat' : 'rdoc'
150
- GEM = WIN32 ? 'gem.bat' : 'gem'
146
+ RCOV = "#{RUBY} -S rcov"
147
+ RDOC = "#{RUBY} -S rdoc"
148
+ GEM = "#{RUBY} -S gem"
151
149
 
152
150
  %w(rcov spec/rake/spectask rubyforge bones facets/ansicode).each do |lib|
153
151
  begin
@@ -162,6 +160,12 @@ HAVE_SVN = (Dir.entries(Dir.pwd).include?('.svn') and
162
160
  HAVE_GIT = (Dir.entries(Dir.pwd).include?('.git') and
163
161
  system("git --version 2>&1 > #{DEV_NULL}"))
164
162
 
163
+ # Add bones as a development dependency
164
+ #
165
+ if HAVE_BONES
166
+ PROJ.gem.development_dependencies << ['bones', ">= #{Bones::VERSION}"]
167
+ end
168
+
165
169
  # Reads a file at +path+ and spits out an array of the +paragraphs+
166
170
  # specified.
167
171
  #
@@ -243,9 +247,29 @@ end
243
247
  # Scans the current working directory and creates a list of files that are
244
248
  # candidates to be in the manifest.
245
249
  #
246
- def manifest_files
250
+ def manifest
247
251
  files = []
248
- exclude = Regexp.new(PROJ.exclude.join('|'))
252
+ exclude = PROJ.exclude.dup
253
+ comment = %r/^\s*#/
254
+
255
+ # process the ignore file and add the items there to the exclude list
256
+ if test(?f, PROJ.ignore_file)
257
+ ary = []
258
+ File.readlines(PROJ.ignore_file).each do |line|
259
+ next if line =~ comment
260
+ line.chomp!
261
+ line.strip!
262
+ next if line.nil? or line.empty?
263
+
264
+ glob = line =~ %r/\*\./ ? File.join('**', line) : line
265
+ Dir.glob(glob).each {|fn| ary << "^#{Regexp.escape(fn)}"}
266
+ end
267
+ exclude.concat ary
268
+ end
269
+
270
+ # generate a regular expression from the exclude list
271
+ exclude = Regexp.new(exclude.join('|'))
272
+
249
273
  Find.find '.' do |path|
250
274
  path.sub! %r/^(\.\/|\/)/o, ''
251
275
  next unless test ?f, path
data/tasks/spec.rake CHANGED
@@ -1,6 +1,5 @@
1
- # $Id: spec.rake 59 2009-01-23 09:10:01Z dido $
2
1
 
3
- if HAVE_SPEC_RAKE_SPECTASK
2
+ if HAVE_SPEC_RAKE_SPECTASK and not PROJ.spec.files.to_a.empty?
4
3
  require 'spec/rake/verify_rcov'
5
4
 
6
5
  namespace :spec do
data/tasks/svn.rake CHANGED
@@ -1,4 +1,3 @@
1
- # $Id: svn.rake 59 2009-01-23 09:10:01Z dido $
2
1
 
3
2
  if HAVE_SVN
4
3
 
data/tasks/test.rake CHANGED
@@ -1,5 +1,5 @@
1
- # $Id: test.rake 59 2009-01-23 09:10:01Z dido $
2
1
 
2
+ if test(?e, PROJ.test.file) or not PROJ.test.files.to_a.empty?
3
3
  require 'rake/testtask'
4
4
 
5
5
  namespace :test do
@@ -35,4 +35,6 @@ task :test => 'test:run'
35
35
 
36
36
  task :clobber => 'test:clobber_rcov' if HAVE_RCOV
37
37
 
38
+ end
39
+
38
40
  # EOF
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emdrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dido@imperium.ph
@@ -9,10 +9,29 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-04 00:00:00 +08:00
12
+ date: 2009-03-18 00:00:00 +08:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: eventmachine
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.12.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: bones
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.4.2
34
+ version:
16
35
  description: This is a distributed Ruby client and server which should work as a drop-in replacement for the standard distributed Ruby implementation available in the Ruby standard library.
17
36
  email: dido@imperium.ph
18
37
  executables: []
@@ -26,7 +45,6 @@ files:
26
45
  - COPYING
27
46
  - History.txt
28
47
  - LEGAL
29
- - Manifest.txt
30
48
  - README.txt
31
49
  - Rakefile
32
50
  - lib/emdrb.rb
@@ -42,7 +60,6 @@ files:
42
60
  - tasks/bones.rake
43
61
  - tasks/gem.rake
44
62
  - tasks/git.rake
45
- - tasks/manifest.rake
46
63
  - tasks/notes.rake
47
64
  - tasks/post_load.rake
48
65
  - tasks/rdoc.rake
@@ -74,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
91
  requirements: []
75
92
 
76
93
  rubyforge_project: emdrb
77
- rubygems_version: 1.2.0
94
+ rubygems_version: 1.3.1
78
95
  signing_key:
79
96
  specification_version: 2
80
97
  summary: This is a distributed Ruby client and server which should work as a drop-in replacement for the standard distributed Ruby implementation available in the Ruby standard library
data/Manifest.txt DELETED
@@ -1,28 +0,0 @@
1
- COPYING
2
- History.txt
3
- LEGAL
4
- Manifest.txt
5
- README.txt
6
- Rakefile
7
- lib/emdrb.rb
8
- lib/emdrb/emdrb.rb
9
- lib/emdrb/unix.rb
10
- lib/emdrb/version.rb
11
- spec/client_spec.rb
12
- spec/drbserver.rb
13
- spec/server_spec.rb
14
- spec/spec_common.rb
15
- spec/spec_helper.rb
16
- tasks/ann.rake
17
- tasks/bones.rake
18
- tasks/gem.rake
19
- tasks/git.rake
20
- tasks/manifest.rake
21
- tasks/notes.rake
22
- tasks/post_load.rake
23
- tasks/rdoc.rake
24
- tasks/rubyforge.rake
25
- tasks/setup.rb
26
- tasks/spec.rake
27
- tasks/svn.rake
28
- tasks/test.rake
data/tasks/manifest.rake DELETED
@@ -1,49 +0,0 @@
1
- # $Id: manifest.rake 59 2009-01-23 09:10:01Z dido $
2
-
3
- require 'find'
4
-
5
- namespace :manifest do
6
-
7
- desc 'Verify the manifest'
8
- task :check do
9
- fn = PROJ.manifest_file + '.tmp'
10
- files = manifest_files
11
-
12
- File.open(fn, 'w') {|fp| fp.puts files}
13
- lines = %x(#{DIFF} -du #{PROJ.manifest_file} #{fn}).split("\n")
14
- if HAVE_FACETS_ANSICODE and ENV.has_key?('TERM')
15
- lines.map! do |line|
16
- case line
17
- when %r/^(-{3}|\+{3})/; nil
18
- when %r/^@/; Console::ANSICode.blue line
19
- when %r/^\+/; Console::ANSICode.green line
20
- when %r/^\-/; Console::ANSICode.red line
21
- else line end
22
- end
23
- end
24
- puts lines.compact
25
- rm fn rescue nil
26
- end
27
-
28
- desc 'Create a new manifest'
29
- task :create do
30
- files = manifest_files
31
- unless test(?f, PROJ.manifest_file)
32
- files << PROJ.manifest_file
33
- files.sort!
34
- end
35
- File.open(PROJ.manifest_file, 'w') {|fp| fp.puts files}
36
- end
37
-
38
- task :assert do
39
- files = manifest_files
40
- manifest = File.read(PROJ.manifest_file).split($/)
41
- raise "ERROR: #{PROJ.manifest_file} is out of date" unless files == manifest
42
- end
43
-
44
- end # namespace :manifest
45
-
46
- desc 'Alias to manifest:check'
47
- task :manifest => 'manifest:check'
48
-
49
- # EOF