Skip to content

Instantly share code, notes, and snippets.

@ndarilek
Created November 17, 2008 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndarilek/25945 to your computer and use it in GitHub Desktop.
Save ndarilek/25945 to your computer and use it in GitHub Desktop.
Point and laugh as I awkwardly try to bring Authlogic to Waves!
#!/usr/bin/env ruby
#
# Warning: This file is clobbered when you update your
# application with the waves script. Accordingly, you may
# wish to keep your tasks in .rb or .rake files in lib/tasks
require 'rubygems'
WAVES = "#{File.dirname(__FILE__)}/.." unless defined? WAVES
waves = [
WAVES, ENV['WAVES'], './waves'
].compact.map { |dir| File.join(dir, 'lib') }.find { |d|
File.exist? File.join( d, 'waves.rb' )
}
if waves
$: << waves
waves = File.join( waves, 'waves' )
else
waves = 'waves'
end
require waves
require 'runtime/console'
begin
Waves::Console.load(:mode => ENV['mode'])
# load tasks from waves framework
%w( generate gem ).each { |task| require "tasks/#{task}.rb" }
# load tasks from this app's lib/tasks
Dir["lib/tasks/*.{rb,rake}"].each { |task| require task }
rescue LoadError => e
if e.message == 'no such file to load -- waves'
puts "Can't find Waves source. Install gem, freeze Waves, or define WAVES at the top of the Rakefile"
puts
else
raise e
end
end
namespace :waves do
desc "freeze src=<wherever> to ./waves"
task :freeze do
target = "#{Dir.pwd}/waves"
src = ENV['src']
raise "Please specify the location of waves using src=wherever" unless src
raise "No directory found at '#{src}'" unless File.directory?(src)
items = FileList["#{src}/*"]
puts "Freezing from: #{src}"
items.each do |item|
puts "copying #{item}"
cp_r item, target
end
end
desc "unfreeze (i.e. delete) the waves source at ./waves"
task :unfreeze do
frozen = "#{Dir.pwd}/waves"
rm_r frozen if File.exist?(frozen)
end
# Convenience task to allow you to freeze the current Waves
# source without knowing where it is. This task only gets
# defined when the Rakefile successfully loaded Waves and if
# there's nothing in the way at ./waves
if defined?(WAVES) && !File.exist?("#{Dir.pwd}/waves")
namespace :freeze do
desc "freeze current Waves source to ./waves"
task :current do
target = "#{Dir.pwd}/waves"
current = File.expand_path( WAVES )
items = FileList["#{current}/*"]
puts "Freezing from: #{current}"
items.each do |item|
puts "copying #{item}"
cp_r item, target
end
end
end
end
end
require 'foundations/compact'
require "active_record"
require 'authlogic'
require 'markaby'
module Authlogic
module ControllerAdapters
# = Waves Adapter
# Adapts authlogic to work with Waves. The point is to close the gap between what authlogic expects and what the Waves resource module
# provides. Similar to how ActiveRecord has an adapter for MySQL, PostgreSQL, SQLite, etc.
class WavesAdapter < AbstractAdapter
def session
controller.session.to_hash.nil? ? {} : controller.session
end
def request
controller.request.rack_request
end
def cookies
controller.request.rack_request.cookies
end
end
end
end
module Waves
module Resources
module Mixin
class << self
alias_method :orig_included, :included
def included(klass)
orig_included(klass)
klass.before do
Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::WavesAdapter.new(self) unless Authlogic::Session::Base.controller
end
end
end
end
end
end
class Default < ActiveRecord::Migration
def self.up
create_table "users", :force => true do |t|
t.string :login, :null => false
t.string :crypted_password, :null => false
t.string :password_salt, :null => false # not needed if you are encrypting your pw instead of using a hash algorithm.
t.string :remember_token, :null => false
t.string :single_access_token, :null => false # optional, see the single access section below.
t.string :password_reset_token, :null => false # optional, see the password reset section below.
t.integer :login_count # optional, this is a "magic" column, see the magic columns section below
end
end
def self.down
drop_table :users
end
end
module Seawall
include Waves::Foundations::Compact
module Configurations
class Development < Waves::Configurations::Default
database :adapter => "sqlite3", :database => "memory:"
application do
run ::Waves::Dispatchers::Default.new
end
end
end
#module Models
#end
module Resources
class Map
on(:get, true) do
Views.layout do
p "Hello from seawall!"
debugger
if UserSession.find
else
p "Not through the seawall yet."
end
end
end
end
end
module Views
def self.layout(assigns = {}, &block)
Markaby::Builder.new(assigns) do
xhtml_strict do
head { title "Seawall" }
body(&block)
end
end
end
end
end
class User < ActiveRecord::Base
ActiveRecord::Base.establish_connection(Waves.config.database)
Default.up
acts_as_authentic
end
class UserSession < Authlogic::Session::Base
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment