This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
## SERVER (config.ru) | |
## Start with: thin start -V -R config.ru | |
app = proc do |env| | |
[ | |
200, | |
{ | |
'Content-Type' => 'text/html', | |
'Content-Length' => '2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'rubygems' | |
gem 'sinatra', :version => "1.2.0" | |
require 'sinatra' | |
require 'mysql2/em' | |
gem "async_sinatra", :version => "0.5.0" | |
require 'sinatra/async' | |
require "sinatra/async/test" | |
require 'test/unit' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Enumerable | |
# Convenient method instead of checking a.nil? || a.empty? | |
# Example: | |
# nil.emptil? ==> true | |
# [].emptil? ==> true | |
# {}.emptil? ==> true | |
# {:foo => 'bar'}.emptil? ==> false | |
# [1,2,3].emptil? ==> false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveResource | |
class Connection | |
private | |
# Handles response and error codes from the remote service. | |
def handle_response(response) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def provides(*types) | |
types = [types] unless types.kind_of? Array | |
types.map!{|t| mime_type(t)} | |
condition { | |
matching_types = (request.accept & types) | |
unless matching_types.empty? | |
response.headers['Content-Type'] = matching_types.first | |
true | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Padrinotest.controller do | |
controller '/users', :provides => [:json] do | |
get '/' do | |
"foo" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_default_guest_gives_login_screen | |
get '/' | |
assert last_response.ok? | |
assert last_response.body.include?('log in to continue') | |
end | |
----------> | |
context "When accessing / guest should see the login screen" do | |
before :all do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A user have methods for login and such | |
class User < Sequel::Model(:users) | |
end | |
# A administrator is a USER but have extra data in | |
# administrators table. | |
class Administrator < User | |
one_to_one :user | |
set_dataset(:administrators) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Utils | |
# Creates a hash from instance vars | |
def attributes | |
vars = {} | |
instance_variables.each do |var| | |
vars[var.gsub("@", "").to_sym] = instance_variable_get(var) | |
end | |
vars | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Padrino | |
module Reloader | |
module Stat | |
class << self | |
def rotation | |
paths = Dir[Padrino.root("*")].unshift(Padrino.root).reject { |path| !File.directory?(path) } | |
files = paths.map { |path| Dir["#{path}/**/*.rb"] }.flatten.uniq | |
files.map{ |file| |