Skip to content

Instantly share code, notes, and snippets.

# first we will give Domains a little help
class Domain < String
def subdomain( rank = 1 ) ; self.split('.')[0..(rank-1)].join('.') ; end
def level( rank ) ; self.split('.')[(rank*-1)..-1].join('.') ; end
def top_level ; level(1) ; end
end
# now we can treat them like strings but also access domain components naturally
def satisfy?( request )
METHODS.all? do | method |
wanted = instance_variable_get( "@#{method}")
got = request.send( method ) if wanted
wanted.is_a? Proc ? wanted.call( got ) : wanted === got
end
end
class Default
def add ; action( :create ) and redirect( paths.show ) ; end
def update
action( :update, name ) and redirect( resource( :site ).paths.main )
end
def delete
action( :delete, name ) and redirect( resource( :site ).paths.main )
end
def edit ; action( :find, name ) and render( :editor ) } ; end
def show ; action( :find, name ) and render( :show ) ; end
ypcmc02106:pages dyoder$ irb
>> load 'startup.rb'
=> true
>> with
ArgumentError: wrong number of arguments (0 for 1)
from (irb):2:in `with'
from (irb):2
lambda {
string_or_symbol = lambda { |arg| arg.kind_of?(String) || arg.kind_of?(Symbol) }
Waves::ResponseMixin.module_eval do
[ :models, :controllers, :views, :helpers ].each do |k|
functor( k ) { app[ k ] }
functor( k, string_or_symbol ) { |name| app( name )[ k ] }
end
end
}.call
Breakpoint 1 at autocode.rb:52
/opt/local/lib/ruby/gems/1.8/gems/autocode-1.0.0/lib/autocode.rb:52
Kernel.load( path ) unless path.nil?
(rdb:3) path
"helpers/default.rb"
(rdb:3) self
Pages::Helpers
(rdb:3) Kernel.load( path )
true
(rdb:3) const_defined?( :Default )
# special rule to handle rss blog feed
blog.feed when get /blog/:name and accepts rss
with resource = site
authenticated when before get /admin/*
login when get /login
authenticate when post /login
main when get /admin
update when post /admin
before:
authenticated?: { get: /?resource/?name/edit }
blog.feed: { get: /blog/?name, accepts: rss }
default.edit: { get: /?resource/?name/edit }
media.get: { get: /?media/?path[*] }
before do
on( :get => [ 'admin', true ], :resource => :admin ) { authenticated? }
end
after do
...
end
always do
...
module Pages
module Resources
class Default < Waves::Resources::Base
def add
controller.create and redirect( paths.show )
end