rubyrest 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,4 +1,12 @@
1
- *0.0.1*
1
+ == Release 0.0.2
2
+
3
+
4
+ * The engine now starts a daemonized server by default
5
+ * The engine is now embeddable in ruby code, thanks to RubyRest::Engine new implementation.
6
+ * Better HTTP response codes for DELETE and POST
7
+ * Atom formatting now more robust against nil values
8
+
9
+ == Release 0.0.1
2
10
 
3
11
  * Initial release with very basic CRUD facilities
4
12
  * Hello sample application included
data/README CHANGED
@@ -14,7 +14,7 @@ lets you create new REST services without too much effort.
14
14
 
15
15
  To check out the source code:
16
16
 
17
- svn checkout http://rubyrest.rubyforge.org/svn/trunk
17
+ svn checkout svn://rubyforge.org/var/svn/rubyrest/trunk
18
18
 
19
19
  === Contact
20
20
 
@@ -36,6 +36,16 @@ Ruby-on-Rest provides a shell command. Open your console, and type the following
36
36
 
37
37
  rubyrest start|stop <my_service> [<my_service_module>]
38
38
 
39
+ Ruby-on-Rest can also be embedded in ruby code. This is useful for testing purposes:
40
+
41
+ engine = RubyRest::Engine.new( <my_service>, <my_service_module> )
42
+ engine.start
43
+ # ...
44
+ # do some http calls here
45
+ # ...
46
+ engine.stop
47
+
48
+
39
49
  === Configuring your service
40
50
 
41
51
  Ruby-on-Rest will try to load a file name <my_service>.rb which must provide access to
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'fileutils'
6
6
  include FileUtils
7
7
 
8
8
  NAME = "rubyrest"
9
- VERS = "0.0.1"
9
+ VERS = "0.0.2"
10
10
  CLEAN.include ['**/.*.sw?', 'pkg/*', '.config', 'doc/*', 'coverage/*']
11
11
  RDOC_OPTS = ['--quiet', '--title', "Ruby-on-Rest: A simple REST framework for Ruby",
12
12
  "--opname", "index.html",
@@ -25,7 +25,7 @@ Rake::RDocTask.new do |rdoc|
25
25
  rdoc.options += RDOC_OPTS
26
26
  rdoc.main = "README"
27
27
  rdoc.title = "Ruby-on-Rest Documentation"
28
- rdoc.rdoc_files.add ['README', 'COPYING', 'lib/rubyrest.rb', 'lib/rubyrest/**/*.rb', 'examples/**/*.rb' ]
28
+ rdoc.rdoc_files.add ['README', 'COPYING', "CHANGELOG", 'lib/rubyrest.rb', 'lib/rubyrest/**/*.rb', 'examples/**/*.rb' ]
29
29
  end
30
30
 
31
31
  spec = Gem::Specification.new do |s|
@@ -45,7 +45,7 @@ spec = Gem::Specification.new do |s|
45
45
  s.add_dependency('metaid')
46
46
  s.required_ruby_version = '>= 1.8.2'
47
47
 
48
- s.files = %w(COPYING README Rakefile) + Dir.glob("{bin,doc,lib}/**/*")
48
+ s.files = %w(COPYING README CHANGELOG Rakefile) + Dir.glob("{bin,doc,lib}/**/*")
49
49
 
50
50
  s.require_path = "lib"
51
51
  s.bindir = "bin"
@@ -75,9 +75,9 @@ end
75
75
  desc 'Make a release in Rubyforge'
76
76
  task :release => [:clean, :package, :doc_rforge ] do
77
77
  # create a svn tag
78
- sh %{svn copy svn+ssh://rubyforge.org/var/svn/rubyrest/trunk svn+ssh://rubyforge.org/var/svn/rubyrest/tags/#{VERS}}
78
+ sh %{svn copy -m 'TAG: #{VERS}' svn+ssh://rubyforge.org/var/svn/rubyrest/trunk svn+ssh://rubyforge.org/var/svn/rubyrest/tags/#{VERS}}
79
79
  # upload the gem
80
- sh %{scp pkg/#{NAME}-#{VERS}.gem sicozu@rubyforge.org:/var/www/gforge-projects/rubyrest/}
80
+ #sh %{scp pkg/#{NAME}-#{VERS}.gem sicozu@rubyforge.org:/var/www/gforge-projects/rubyrest/}
81
81
  end
82
82
 
83
83
  require 'spec/rake/spectask'
data/bin/rubyrest CHANGED
@@ -6,62 +6,21 @@
6
6
  require 'rubygems'
7
7
  require 'rubyrest'
8
8
 
9
+ service = ARGV[1]
10
+ prefix = ARGV[2]
11
+ action = ARGV[0]
9
12
 
10
- module RubyRest
11
-
12
-
13
- class RubyRestBoot
14
- include RubyRest::Tools
15
-
16
- def initialize( option, service, prefix = nil )
17
-
18
- if option == nil or service == nil or !self.respond_to?( option )
19
- help_and_exit
20
- return
21
- end
22
-
23
- @option = option
24
- @service = service
25
- @service_prefix = prefix
26
-
27
- #begin
28
- self.method( @option ).call
29
- #rescue => e
30
- # puts "ERROR #{e.message}"
31
- #end
32
-
33
- end
34
-
35
- def help_and_exit
36
- puts "Usage: rubyrest start|stop <your_service> "
37
- puts "Ruby-on-Rest: Simple REST for Ruby."
38
- puts
39
- puts "Examples:"
40
- puts " rubyrest start grape"
41
- puts " rubyrest stop grape"
42
- puts
43
- puts "For more information see http://rubyrest.rubyforge.org"
44
- end
45
-
46
- def start
47
- service_module = to_module_name( @service_prefix, @service )
48
- require @service
49
- puts "=> Starting service '#{@service}' in module '#{service_module}'"
50
- config = to_class( service_module, "config" ).new
51
- config[ :servicemodule ] = service_module
52
- RubyRest::Engine.new( config ).start
53
- puts "=> Service #{@service} running!"
54
- end
55
-
56
-
57
- def stop
58
- puts "=> Stopping service #{@service}..."
59
-
60
-
61
- puts "=> Service #{@service} stopped!"
62
- end
63
-
64
- end
13
+ if action == nil or ( action != "start" and action != "stop" ) or service == nil
14
+ puts "Usage: rubyrest start|stop <your_service> "
15
+ puts "Ruby-on-Rest: Simple REST for Ruby."
16
+ puts
17
+ puts "Examples:"
18
+ puts " rubyrest start grape"
19
+ puts " rubyrest stop grape"
20
+ puts
21
+ puts "For more information see http://rubyrest.rubyforge.org"
22
+ else
23
+ engine = RubyRest::Engine.new( service, prefix )
24
+ engine.method( action ).call
65
25
  end
66
26
 
67
- RubyRest::RubyRestBoot.new( ARGV[0], ARGV[1], ARGV[2] )
data/lib/rubyrest/atom.rb CHANGED
@@ -92,10 +92,13 @@ module RubyRest
92
92
  builder.summary object.atom_summary
93
93
  builder.link( "rel" => "alternate", "href" => entry_link )
94
94
 
95
- if object.respond_to? :atom_related
96
- object.atom_related.each{ |related|
95
+ if object.respond_to?( :atom_related )
96
+ related_entities = object.atom_related
97
+ if related_entities.respond_to?( :each )
98
+ related_entities.each{ |related|
97
99
  builder.link( "rel" => "related", "href" => "#{entry_link}/#{related}", "title" => "#{related}", "type" => ATOM_TYPE )
98
- }
100
+ }
101
+ end
99
102
  end
100
103
 
101
104
  builder.moodisland :content do
@@ -8,27 +8,43 @@ module RubyRest
8
8
  # Objects of this class take a configuration as argument
9
9
  # then launch a new server instance.
10
10
  class Engine
11
+ include Tools
11
12
 
12
13
  # Enables external objects to read the
13
14
  # engine configuration
14
15
  attr_reader :config
15
16
 
16
- # Creates a new RubyRest engine, for the specified
17
- # configuration
18
- def initialize( config )
19
- @config = config
17
+ # Creates a new RubyRest engine, for the service
18
+ # and service prefix
19
+ def initialize( service, prefix = nil )
20
+ @service = service
21
+ @prefix = prefix
22
+ service_module = to_module_name( @prefix, @service )
23
+ require @service
24
+ @config = to_class( service_module, "config" ).new
25
+ @config[ :servicemodule ] = service_module
20
26
  end
21
27
 
22
- # Starts the engine.
23
- # The following operations are accomplished:
28
+ # Starts the engine. The following operations are accomplished:
24
29
  #
25
- # 1. establish a connection to the database
26
- # 2. initialize the database schema
27
- # 3. load initial data into the database
28
- #
30
+ # 1. configure the database
31
+ # 2. launch the webserver, in daemon mode unless false is
32
+ # specified in the configuration
29
33
  def start
30
34
  configure_database if @config.has( :dbadapter )
31
- start_server
35
+ @server = RubyRest::Server.new( @config )
36
+ @server.mount "/", CRUDServlet
37
+ if @config.has( :daemon ) and @config[ :daemon ] == false
38
+ start_server
39
+ else start_daemon end
40
+ end
41
+
42
+ # Shutdowns the current server, if existing.
43
+ # This is only useful when working in daemon mode.
44
+ def stop
45
+ return if @pid == nil
46
+ Process.kill( 9, @pid )
47
+ puts "#{self.to_s}: killed process with pid=#{@pid}"
32
48
  end
33
49
 
34
50
  # Configures the database connectivity
@@ -41,16 +57,25 @@ module RubyRest
41
57
  end
42
58
  end
43
59
 
44
- # Configures and returns a new web server
45
- # instance. For the moment, only WEBrick instances
46
- # are supported
60
+ # Starts the server in another process
61
+ def start_daemon
62
+ @pid = fork do
63
+ start_server
64
+ end
65
+ puts "#{self.to_s}: started process with pid=#{@pid}"
66
+ end
67
+
68
+ # Starts the server
47
69
  def start_server
48
- server = RubyRest::Server.new( @config )
49
70
  [ "INT", "TERM" ].each { |signal|
50
- trap( signal ) { server.shutdown }
71
+ trap( signal ) { @server.shutdown }
51
72
  }
52
- server.mount "/", CRUDServlet
53
- server.start
73
+ @server.start
74
+ end
75
+
76
+ # Returns the service name
77
+ def to_s
78
+ "rubyrest: #{@service}"
54
79
  end
55
80
 
56
81
  end
@@ -72,7 +72,6 @@ module RubyRest
72
72
  else
73
73
  response.status = @success_code
74
74
  format_response( request, response ) if @result != nil
75
- raise WEBrick::HTTPStatus::OK
76
75
  end
77
76
  end
78
77
 
@@ -114,7 +113,7 @@ module RubyRest
114
113
  resolve_params( request )
115
114
  incompatible_path( request ) if @id == nil
116
115
  @generic_method = :delete
117
- @success_code = 200
116
+ @success_code = 410
118
117
  dispatch( request, response )
119
118
  end
120
119
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.1
3
3
  specification_version: 1
4
4
  name: rubyrest
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2007-03-28 00:00:00 +02:00
6
+ version: 0.0.2
7
+ date: 2007-03-30 00:00:00 +02:00
8
8
  summary: REST framework for Ruby.
9
9
  require_paths:
10
10
  - lib
@@ -31,6 +31,7 @@ authors:
31
31
  files:
32
32
  - COPYING
33
33
  - README
34
+ - CHANGELOG
34
35
  - Rakefile
35
36
  - bin/rubyrest
36
37
  - doc/rdoc
@@ -41,7 +42,6 @@ files:
41
42
  - lib/rubyrest/engine.rb
42
43
  - lib/rubyrest/servlets.rb
43
44
  - lib/rubyrest/tools.rb
44
- - CHANGELOG
45
45
  - examples/hello.rb
46
46
  test_files: []
47
47