Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
For mister_solo, as a reply to a question on #ruote (freenode irc)

Setup

This is my ruote / ruote-kit setup in non Rails project

A Project Module

I tend to have a Project Module for my non-web projects; so that instead of calling Rails.logger I call Project.logger (Where Project would be the actual name, Such as Fubar or SameOld) same goes for ruote. It mostly ends-up in Project.engine where the code would look something like this:

module Project
  class << self
    attr_accessor :config, :root

    def engine
      @engine ||= setup_ruote_engine
    end

    def setup_ruote_engine
      Ruote::Engine.new(
        Ruote::Worker.new(
          Ruote::FsStorage.new(File.join(Project.root, Project.config[:ruote][:storage]))
        )
      )
    end

    def logger
      @logger ||= setup_logger
    end

    def setup_logger
      logger = Logger.new File.join(Project.root, Project.config[:log_file])
      logger.formatter = proc { |severity, datetime, progname, msg|
        "[#{datetime}] #{severity}: #{msg}\n"
      }
      return logger
    end

    # etc. etc.
  end
end

combine that with a nice Yaml file for config and you're half way there.

Boot

Another 'Rails Convention' I tend to steal is to have a boot file, where I load up my Project module

# require everything
require 'bundler/setup'
Bundler.require

# core dependencies
require 'logger'


# load paths
root   = File.expand_path('../../', __FILE__)
lib    = File.join(root, "lib")
config = File.join(root, "config")

# setup the project
require File.join(lib, "project")
Project.root   = root
Project.config = YAML.load_file(File.join(config, "project.yml"))

# ... project specific requires go here

Rack it up

Now that I have seperated and comparted everything, my rack-up file is plain and simple

require './config/boot'

RuoteKit.engine = Project.engine
RuoteKit.engine.register do
  catchall
end

use Rack::CommonLogger
use Rack::Lint

run RuoteKit::Application

And for convenience; a shell script

#!/bin/sh

/usr/bin/env rackup -p 9494 script/config.ru

A listing for completion

./lib
./lib/project.rb
./config
./config/boot.rb
./config/project.yml
./script
./script/ruote_web     # the shell script - I tend to drop the extension on executables
./script/config.ru
./data
./data/ruote_work      # ruote storage directory, configured in project.yml

Hope that is insightfull, helpfull

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.