Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Big steps in removing daemon-kit, starting to map resources to /_ruote

  • Loading branch information...
commit 29e6e1659e788fb401b219a8f9bf2c9317979b51 1 parent 4d83c8c
@kennethkalmer authored
View
5 Gemfile
@@ -1,12 +1,7 @@
# Dependencies for ruote-kit
-# stick to an older EM because of thin issues (or is it just me?)
-gem 'eventmachine', '0.12.8'
-
# ruote-kit itself
-gem 'daemon-kit'
gem 'sinatra'
-gem 'eventmachine'
gem 'haml'
gem 'json'
View
3  Rakefile
@@ -1,6 +1,3 @@
-require File.dirname(__FILE__) + '/config/boot'
-
require 'rake'
-require 'daemon_kit/tasks'
Dir[File.join(File.dirname(__FILE__), 'tasks/*.rake')].each { |rake| load rake }
View
100 lib/ruote-kit.rb
@@ -1,6 +1,4 @@
-# Your starting point for daemon specific classes. This directory is
-# already included in your load path, so no need to specify it.
-
+require 'json'
require 'ruote'
module RuoteKit
@@ -15,66 +13,69 @@ class << self
# The instance of ruote
attr_accessor :engine
- # Instance of our sinatra app
- attr_accessor :sinatra
+ # The instance of our worker, if used
+ attr_accessor :worker
- # Instance of server handler
- attr_accessor :server
+ def env
+ @env ||= (
+ if defined?( Rails )
+ Rails.env
+ else
+ ENV['RACK_ENV'] || 'development'
+ end
+ )
+ end
- # Instance of our server thread
- attr_accessor :server_thread
+ def root
+ Dir.pwd
+ end
+
+ def configure( &block )
+ configuration.instance_eval &block
+
+ run_engine! if configuration.run_engine
+ end
# Configure and run the engine in a RESTful container
def run!(&block)
yield if block_given?
- configure_engine
- configure_sinatra
- running!
+ run_engine!
end
def shutdown!( purge_engine = false )
- shutdown_sinatra
shutdown_engine( purge_engine )
end
def configuration
- unless @configuration
- @configuration = Configuration.new
- config = @configuration
- eval( IO.read( @configuration.user_file ), binding, @configuration.user_file ) if File.exist?( @configuration.user_file )
- end
-
- @configuration
- end
- def access_logger
- if configuration.access_log
- return DaemonKit::AbstractLogger.new( configuration.access_log )
- end
+ @configuration ||= Configuration.new
end
def configure_participants
self.engine.register_participant('.*', configuration.catchall_participant)
end
- def configure_engine
- DaemonKit.logger.debug "Configuring engine & storage"
+ def ensure_engine!
+ run_engine! if self.engine.nil?
+ end
+
+ def run_engine!
storage = configuration.storage_instance
self.engine = Ruote::Engine.new( storage )
configure_participants
- return if %w(test cucumber).include? DaemonKit.env
+ return unless configuration.run_worker
- DaemonKit.logger.debug "Starting a worker"
- worker = Ruote::Worker.new( storage )
- worker.run_in_thread
+ self.worker = Ruote::Worker.new( storage )
+ self.worker.run_in_thread
end
def shutdown_engine( purge = false )
- DaemonKit.logger.debug "Shutting down engine"
+
+ return if self.engine.nil?
self.engine.shutdown
@@ -86,41 +87,10 @@ def shutdown_engine( purge = false )
end
self.engine = nil
- end
-
- private
-
- def configure_sinatra
- DaemonKit.logger.debug "Configuring Sinatra"
-
- Encoding.default_external = Encoding::ASCII_8BIT if ''.respond_to?(:force_encoding)
-
- self.sinatra = RuoteKit::Application
-
- return if %w(test cucumber).include? DaemonKit.env
-
- self.server_thread = Thread.new {
- configuration.rack_handler_class.run( self.sinatra, configuration.rack_options ) do |server|
- self.server = server
- end
- }
- end
-
- def running!
- DaemonKit.at_shutdown do
- RuoteKit.shutdown!
- end
- self.server_thread.join if self.server_thread
+ self.worker.shutdown if self.worker
+ self.worker = nil
end
- def shutdown_sinatra
- DaemonKit.logger.debug "Shutting down Sinatra"
-
- return if %w( test cucumber ).include? DaemonKit.env
-
- self.server.respond_to?(:stop!) ? self.server.stop! : self.server.stop
- self.server_thread.join
- end
end
end
View
20 lib/ruote-kit/application.rb
@@ -1,17 +1,19 @@
-require 'sinatra/respond_to'
+require 'ruote-kit/vendor/sinatra-respond_to/lib/sinatra/respond_to'
+require 'haml'
module RuoteKit
class Application < Sinatra::Base
- set :environment, DaemonKit.env
- set :views, DaemonKit.root + '/lib/ruote-kit/views'
- set :public, DaemonKit.root + '/lib/ruote-kit/public'
- set :static, true
+ configure do
+ set :environment, Rails.env if defined?( Rails )
- use Rack::CommonLogger, RuoteKit.access_logger
- use Rack::Lint
+ RuoteKit.ensure_engine!
+ end
+
+ set :views, File.join( File.dirname( __FILE__), 'views' )
+
+ use Rack::Static, :urls => ['/_ruote/images', '/_ruote/javascripts', '/_ruote/stylesheets'], :root => File.join( File.dirname(__FILE__), 'public' )
use Rack::MethodOverride
- use Rack::ShowExceptions
helpers do
include RuoteKit::Helpers::EngineHelpers
@@ -30,7 +32,7 @@ class Application < Sinatra::Base
resource_not_found
end
- get '/' do
+ get '/_ruote' do
respond_to do |format|
format.html { haml :index }
format.json { json :misc, "ruote-kit" => "welcome", "version" => RuoteKit::VERSION }
View
45 lib/ruote-kit/configuration.rb
@@ -2,38 +2,22 @@ module RuoteKit
# RuoteKit configuration handling
class Configuration
- attr_accessor :rack_handler
-
- attr_accessor :rack_options
-
- # Path the access log for Rack::CommonLogger
- attr_accessor :access_log
-
# Working directory for the engine (if using file system persistence)
attr_accessor :work_directory
# Number of workers to spawn (1 by default)
attr_accessor :workers
- class << self
+ # Whether to run the engine or not (defaults to true)
+ attr_accessor :run_engine
- # Default rack handlers to make use of
- def fallback_handlers
- @fallback_handlers ||= [ 'thin', 'webrick' ]
- end
-
- end
+ # Whether to run a single worker or not (defaults to false)
+ attr_accessor :run_worker
def initialize
- self.rack_handler = :thin
-
- self.rack_options = {
- :port => 9292
- }
-
- self.work_directory = File.join( DaemonKit.root, "work_#{DaemonKit.env}" )
-
- self.workers = 1
+ self.work_directory = File.join( RuoteKit.root, "work_#{RuoteKit.env}" )
+ self.run_engine = true
+ self.run_worker = false
end
# Return the selected ruote-kit mode
@@ -47,11 +31,6 @@ def mode=( mode )
@mode = mode
end
- # Path to user-specific configuration
- def user_file
- File.join( DaemonKit.root, 'config', 'ruote.rb' )
- end
-
# Return the best suited storage class for the current mode
def storage_instance
case mode
@@ -69,15 +48,5 @@ def catchall_participant
Ruote::StorageParticipant
end
- def rack_handler_class
- begin
- Rack::Handler.get( self.rack_handler.to_s )
- rescue NameError
- unless self.class.fallback_handlers.empty?
- self.rack_handler = self.class.fallback_handlers.shift
- retry
- end
- end
- end
end
end
View
26 lib/ruote-kit/views/layout.html.haml
@@ -2,16 +2,16 @@
%html
%head
%title ruote-kit
- %link{ :type => "text/css", :href => "/stylesheets/base.css", :rel => "stylesheet" }
- %link{ :type => "text/css", :href => "/stylesheets/style.css", :rel => "stylesheet" }
- %link{ :type => "text/css", :href => "/stylesheets/SimplyButtons.css", :rel => "stylesheet" }
- %link{ :type => "text/css", :href => "/stylesheets/rk.css", :rel => "stylesheet" }
- %script{ :type => "text/javascript", :src => "/javascripts/SimplyButtons.js" }
+ %link{ :type => "text/css", :href => "/_ruote/stylesheets/base.css", :rel => "stylesheet" }
+ %link{ :type => "text/css", :href => "/_ruote/stylesheets/style.css", :rel => "stylesheet" }
+ %link{ :type => "text/css", :href => "/_ruote/stylesheets/SimplyButtons.css", :rel => "stylesheet" }
+ %link{ :type => "text/css", :href => "/_ruote/stylesheets/rk.css", :rel => "stylesheet" }
+ %script{ :type => "text/javascript", :src => "/_ruote/javascripts/SimplyButtons.js" }
- if @_uses_fluo
- %script{ :type => "text/javascript", :src => "/javascripts/fluo-can.js" }
- %script{ :type => "text/javascript", :src => "/javascripts/fluo-dial.js" }
- %script{ :type => "text/javascript", :src => "/javascripts/fluo-json.js" }
- %script{ :type => "text/javascript", :src => "/javascripts/fluo-tred.js" }
+ %script{ :type => "text/javascript", :src => "/_ruote/javascripts/fluo-can.js" }
+ %script{ :type => "text/javascript", :src => "/_ruote/javascripts/fluo-dial.js" }
+ %script{ :type => "text/javascript", :src => "/_ruote/javascripts/fluo-json.js" }
+ %script{ :type => "text/javascript", :src => "/_ruote/javascripts/fluo-tred.js" }
:javascript
window.onload = function() { SimplyButtons.init(); }
@@ -22,12 +22,12 @@
#user-navigation
%ul
%li
- %a{ :href => "/processes/new" } Launch a new process
+ %a{ :href => "/_ruote/processes/new" } Launch a new process
#main-navigation
%ul
- = navigate_to "Processes", "/processes"
- = navigate_to "Expressions", "/expressions"
- = navigate_to "Workitems", "/workitems"
+ = navigate_to "Processes", "/_ruote/processes"
+ = navigate_to "Expressions", "/_ruote/expressions"
+ = navigate_to "Workitems", "/_ruote/workitems"
.clear
#wrapper
#main
View
4 spec/resources/index_spec.rb
@@ -2,7 +2,7 @@
describe "GET /" do
it "should return a welcome message in HTML be default" do
- get "/"
+ get "/_ruote"
last_response.should be_ok
last_response.content_type.should match("text/html")
@@ -14,7 +14,7 @@
it "should return a version string if JSON is requested" do
header "Accept", "application/json"
- get "/"
+ get "/_ruote"
last_response.should be_ok
last_response.content_type.should match("application/json")
View
18 spec/spec_helper.rb
@@ -1,4 +1,3 @@
-ENV['DAEMON_ENV'] = 'test'
ENV['RACK_ENV'] = 'test'
begin
@@ -16,9 +15,16 @@
Test::Unit::TestCase.send :include, Rack::Test::Methods
-require File.dirname(__FILE__) + '/../config/environment'
-DaemonKit::Application.running!
-RuoteKit.run!
+require File.dirname(__FILE__) + '/../vendor/gems/environment' if File.exists?( File.dirname(__FILE__) + '/../vendor/gems/environment.rb' )
+require File.dirname(__FILE__) + '/../lib/ruote-kit'
+
+RuoteKit.configure do
+
+ # In memory is perfect for tests
+ mode = :transient
+
+ p [ :rk_configure ]
+end
require 'ruote-kit/spec/ruote_helpers'
require 'ruote/log/test_logger'
@@ -44,7 +50,7 @@
end
config.before(:each) do
- RuoteKit.configure_engine
+ RuoteKit.run_engine!
@tracer = Tracer.new
RuoteKit.engine.add_service( 'tracer', @tracer )
@@ -69,7 +75,7 @@
end
def app
- RuoteKit.sinatra
+ RuoteKit::Application
end
# Sets the local variables that will be accessible in the HAML

0 comments on commit 29e6e16

Please sign in to comment.
Something went wrong with that request. Please try again.