SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 254 | Next

Ola Bini

"Practical JRuby on Rails Web 2.0 Projects: Bringing Ruby on Rails to Java"

current(arg)
when :list: Sequence.find(:all).map{|s| s.name}
else nil
end
end
At the moment, none of these invocations will work, because you haven??™t added the necessary
helper methods to the Sequence class yet. However, before you go ahead and do that,
you should provide some way to test the sequences. At the bottom of the file, add this code:
if __FILE__ == $0
p BBEngine.new("admin","admin","create").invoke("seq1")
ninv = BBEngine.new("admin","admin","next")
p ninv.invoke("seq1")
p ninv.invoke("seq1")
p ninv.invoke("seq1")
p BBEngine.new("olagus","admin","admin").invoke("seq1")
p ninv.invoke("seq1")
p BBEngine.new("admin","admin","last_updated").invoke("seq1")
p BBEngine.new("admin","admin","current").invoke("seq1")
p BBEngine.new("admin","admin","current").invoke("seq1")
p BBEngine.new("admin","admin","current").invoke("seq1")
p BBEngine.new("admin","admin","last_updated_by").invoke("seq1")
end
The code that compares $0 to the value of __FILE__ is a common Ruby idiom. It checks
if the currently executing file is the program running, or has been required from some other
program. It??™s common for Ruby libraries to add code such as this, which tests the implementation,
if the code in question isn??™t used as a library.
CHAPTER 9 ?–  A JRUBY ENTERPRISE BEAN 172
So, finally you need to add the rest of the Sequence implementation. Let??™s start with the
next method:
def self.next(user, name)
f = find_by_name(name)
return f.next(user) if f
end
def next(user)
transaction do
ss = self.


Pages:
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266