Skip to content

Commit

Permalink
Application
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagopradi committed Jul 30, 2010
1 parent b0c8eb6 commit fa7defa
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 7 deletions.
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source :gemcutter

gem "sinatra"
gem "haml"
gem "ar-octopus", "0.0.29", :require => "octopus"
gem "activerecord", '>= 2.3'
gem "sqlite3-ruby", ">= 1.3.1"
gem "sinatra-activerecord", :git => "git://github.com/tchandy/sinatra-activerecord.git"
30 changes: 30 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
GIT
remote: git://github.com/tchandy/sinatra-activerecord.git
revision: 47726c2
specs:
sinatra-activerecord (0.1.2)

GEM
remote: http://rubygems.org/
specs:
activerecord (2.3.8)
activesupport (= 2.3.8)
activesupport (2.3.8)
ar-octopus (0.0.29)
activerecord (>= 2.3)
haml (3.0.15)
rack (1.2.1)
sinatra (1.0)
rack (>= 1.0)
sqlite3-ruby (1.3.1)

PLATFORMS
ruby

DEPENDENCIES
activerecord (>= 2.3)
ar-octopus (= 0.0.29)
haml
sinatra
sinatra-activerecord!
sqlite3-ruby (>= 1.3.1)
21 changes: 21 additions & 0 deletions README.mkdn
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Octopus Sinatra Example

This is a sample application using octopus + sinatra. This app demonstrate the basics of octopus running outside Rails.

## How to Run:
<pre>
git clone
cd octopus_sinatra
bundle install
rake db:migrate
rackup
</pre>

## Thanks

This project is sponsored by the <a href="http://www.rubysoc.org">Ruby Summer of Code</a>,
and my mentors <a href="http://github.com/mperham">Mike Perham</a> and <a href="http://github.com/amitagarwal">Amit Agarwal</a>.

## Copyright

Copyright (c) 2010 Thiago Pradi, released under the MIT license.
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# require your app file first
require "rubygems"
require 'server'
require 'rubygems'
require 'bundler'
Bundler.setup

require 'sinatra'
require 'server'
require 'sinatra/activerecord/rake'
7 changes: 7 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'rubygems'
require 'bundler'
Bundler.setup

require 'sinatra'
require 'server'
run Sinatra::Application
6 changes: 3 additions & 3 deletions config/shards.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
octopus:
shards:
america:
adapter: sqlite
adapter: sqlite3
database: america.sqlite3
europe:
adapter: sqlite
adapter: sqlite3
database: europe.sqlite3
asia:
adapter: asia
adapter: sqlite3
database: asia.sqlite3
8 changes: 8 additions & 0 deletions database_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => "master.sqlite3")

class User < ActiveRecord::Base
end

class OrmInfo
def self.build(shard)
Octopus.using(shard.to_sym) do
User.find_by_name("Octopus")
end
end
end
16 changes: 16 additions & 0 deletions db/migrate/20100723210723_create_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class CreateUsers < ActiveRecord::Migration
using(:master, :europe, :asia, :america)

def self.up
create_table :users, :force => true do |t|
t.string :name
t.timestamps
end

User.create(:name => "User #{rand}")
end

def self.down
drop_table :users
end
end
8 changes: 4 additions & 4 deletions server.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require "rubygems"
gem 'activerecord', '2.3.8'
require "sinatra"
require "database_connection"
require 'haml'

get "/" do

haml :welcome
end

get "/database/:shard" do
Octopus.using(params[:shard].to_sym) do

end
haml :database
end
28 changes: 28 additions & 0 deletions views/database.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
!!! Strict
%html
%head
%meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'}
%title Sinatra Octopus Example
%body
#container
#header
%h1 Sinatra Octopus Example
#user-navigation
%ul.wat-cf
Octopus + Sinatra = Awesome!
<div id="main-navigation">
<ul class="wat-cf"></ul>
</div>
#wrapper.wat-cf
.flash
#main
Infos about your shard:
%p= "Name: #{params[:shard]}"
%p
= OrmInfo.build(params[:shard])
- User.using(params[:shard].to_sym).all.each do |user|
%p= "User Id: #{user.id} Name: #{user.name}"
#footer
.block
<p>Copyright &copy; #{ Time.now.year } Thiago Pradi.</p>
#sidebar
Empty file removed views/database.html.haml
Empty file.
30 changes: 30 additions & 0 deletions views/welcome.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
!!! Strict
%html
%head
%meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'}
%title Sinatra Octopus Example
%body
#container
#header
%h1 Sinatra Octopus Example
#user-navigation
%ul.wat-cf
Octopus + Sinatra = Awesome!
<div id="main-navigation">
<ul class="wat-cf"></ul>
</div>
#wrapper.wat-cf
.flash
#main
Hi! Welcome to the sinatra replication Example! Please select what shard you want to use:
%p
%a{:href => '/database/america'} America
%p
%a{:href => '/database/europe'} Europe
%p
%a{:href => '/database/asia'} Asia
#footer
.block
<p>Copyright &copy; #{ Time.now.year } Thiago Pradi.</p>
#sidebar

Empty file removed views/welcome.html.haml
Empty file.

0 comments on commit fa7defa

Please sign in to comment.