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
Router.prepare do |r| | |
r.match("/something", | |
:user_agent => %r[(?:one|two|three)] | |
).to(:controller => "foo", :action => "bar") | |
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
Router.prepare do |r| | |
r.match(:controller => "users") do | |
r.match("/users/:id", :method => :get).to(:action => "show") | |
r.match("/users/:id", :method => :put).to(:action => "update") | |
end | |
end | |
# Both routes generate the exact same path, so do we just | |
# require the minimum necessary to differentiate them? |
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
# NOTE, all names, syntax, etc... are just off the top of my head to illustrate | |
# the general idea. Don't take anything too literally. | |
# I just started a blank project with DataMapper. DM Migrations knows | |
# that the current production database is empty because no schema has been "committed". | |
# | |
# I then created a new model: | |
class User | |
include DataMapper::Resource |
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
describe '#save' do | |
describe 'with a new resource' do | |
it "should create when the resource is dirty" do | |
Zoo.new(:city => "San Diego").save | |
Zoo.first.name.should == "San Diego" | |
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
# current behavior | |
zoo1 = Zoo.new(:city => "SF") | |
zoo2 = Zoo.new(:city => "SF") | |
zoo1.eql?(zoo2) # => true | |
zoo1.save | |
zoo2.save | |
zoo1.eql?(zoo2) # => 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
class Users < Application | |
# === Option 1 === | |
def create | |
@user = User.first | |
User.allow_access(:staff) do | |
@user.update_attributes :staff => true | |
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
class Users < Application | |
def update | |
@user = User.find(params[:id]) | |
if @user.with_access_to(:staff, :banned).update_attributes(params[:user]) | |
# success | |
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
r.match(:domain => "admin") do |admin| | |
admin.match("/users").to(:controller => "admin/users") | |
end | |
r.match(:domain => "site") do |site| | |
site.match("/users").to(:controller => "site/users") | |
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'dm-core' | |
class Zoo | |
include DataMapper::Resource | |
property :id, Serial | |
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
Merb::Router.prepare do |r| | |
r.domain(:admin, "admin.domain.com") do |a| | |
a.resources :users | |
end | |
r.domain(:site, "domain.com") do |s| | |
s.resources :users | |
end | |
OlderNewer