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
//Syntax Sugar------------------------------------------- | |
Object.metaClass.addRole = {role-> | |
delegate.metaClass.mixin role | |
} | |
//Model classes and the database------------------------- | |
class User { | |
int id | |
String name | |
int age |
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
AssertionFailed := Exception clone | |
// -------------------------------------------------------------------------- | |
SpecDefinition := Object clone | |
SpecDefinition new := method(name, | |
r := SpecDefinition clone | |
r name := name |
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
require 'bunny' | |
# connecting to a broker | |
b = Bunny.new({}, {:spec => "09"}) | |
b.start | |
# setup | |
e = b.exchange("exchange-01") | |
q = b.queue("queue-01") | |
q.bind e |
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
require 'bunny' | |
# connecting to a broker | |
b = Bunny.new({}, {:spec => "09"}) | |
b.start | |
# setup | |
e = b.exchange("exchange-02", :durable => true) | |
q = b.queue("queue-02") | |
q.bind e |
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
require 'bunny' | |
# connecting to a broker | |
b = Bunny.new({}, {:spec => "09"}) | |
b.start | |
# setup | |
e = b.exchange("exchange-03") | |
q = b.queue("queue-03") | |
q.bind e |
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
require 'bunny' | |
b = Bunny.new({}, {:spec => "09"}) | |
b.start | |
# setup | |
e = b.exchange("exchange-04") | |
q1 = b.queue("queue-04-01") | |
q1.bind e |
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 update | |
p = Person.find(params[:id]) | |
if p.update_bank_information params[:bank_information] | |
render :json => p.as_json | |
else | |
render :json => "some kind of error" | |
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 PersonJsonSerializer | |
def self.as_json person | |
if person.errors.present? | |
person.as_json(:root => "root-attrs") | |
else | |
{:errors => person.errors.full_messages} | |
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 update | |
p = Person.find(params[:id]) | |
p.update_bank_information params[:bank_information] | |
render :json => PersonJsonSerializer.as_json(p) | |
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 sell_book | |
@book = Book.find(params[:id]) | |
if book.sold? | |
book.errors.add :base, "The book is already sold" | |
else | |
book.sell | |
end | |
end |
OlderNewer