Class instance variable for ruby modules

Sorry if the title is a bit misleading, but this post talks about the scenario such that I have several classes, all extending the same module, and I need to avoid using shared or class variables (@@) in the module because the classes extending the module may change the shared or class variable at the same time and cause problem. So basically we have: class Test   extend TestModule end class TestTwo   extend TestModule end module TestModule   @@val   def somemethod      #do something with @@val   end  end  And the goal is the replace the @@val class variable with a class … Continue reading Class instance variable for ruby modules

Don’t forget the port number when replicating CouchDB

In the afternoon I needed to replicate a database  from my co-worker’s CoudhDB using CouchDBX. In the replicator, I entered my co-worker’s database’s path like the following: http://10.0.0.3/TestDatabase And I selected to replicate to one of my existing databases.  Everything seemed to be right (I could ping and telnet my co-worker’s IP and CouchDB port 5984 without problem), but CouchDBX returned error 500, could not connect to remote database. After a series of diagnostics, we finally realized, we forgot to put the port number in the path of remote database. When we changed the database path to http://10.0.0.3:5984/TestDatabase,  everything just worked … Continue reading Don’t forget the port number when replicating CouchDB

Creating a Merb Rack middleware for running in Merb applications

There are a lot of resources on the Internet showing how to write and run a standalone rack application or middleware, but few showing how to write one to run in other Merb applications. This is actually very easy, so I’m going to share how I did it. Hopefully to be helpful to people in such need. The goal is to have a rack middleware in a merb application, which can be installed as gem, and then can be ued in other merb applications. First, create the merb application: $ merb-gen app application_name where application_name is your proposed application name. … Continue reading Creating a Merb Rack middleware for running in Merb applications

Modify bind address for couchdb 0.9.0

By default couchdb only binds to 127.0.0.1 so it’s not accepting requests from other IP addresses. The bind address setting can be modified in the configuration file. For 0.9.0, by default, the default configuration file is located at /usr/local/etc/couchdb/default.ini, and the local configuration file is located at /usr/local/etc/couchdb/local.ini. Settings in the local configuration file will override those in the default one.  Bind address is in the [httpd] section [httpd] port = 5984 bind_address = 127.0.0.1 Note that in the local configuration file, this may be commented out with a leading “;”, if you want to set it in the local … Continue reading Modify bind address for couchdb 0.9.0

Making an executable standalone Merb Slice gem

I have a standalone Merb Slice which can be started by running the “slice” command in its top directory. Today I needed to make a gem file for this Slice so that people can install the gem and start it directly by running the Slice’s name, for example, “foo”. So I created the Rakefile, in which I specified the executable file in the following way: — Code: Rakefile — spec = Gem::Specification.new do |s|  s.rubyforge_project = ‘merb’  s.name = GEM_NAME  s.version = GEM_VERSION  s.platform = Gem::Platform::RUBY  s.has_rdoc = false  s.summary = SUMMARY  s.description = s.summary  s.author = AUTHOR  s.email = … Continue reading Making an executable standalone Merb Slice gem

Testing exceptions with RSpec

I’m new to ruby and rspec. I wrote a ruby function and wanted to check whether it throws an exception or not in a certain situation with rspec, but I realized should_raise function no longer worked in the rspec version I was using (1.2.2). I tried to find information on the Internet and I found that I should use raise_error. However, when I wrote something like: it “description” do    ObjectName.new(“parameterName”).should raise_error end It did not work. Finally I learned the correct way – using lambda: it “description” do    lambda{ObjectName.new(“parameterName”)}.should raise_error end Wanted to post this here and hope it can be … Continue reading Testing exceptions with RSpec

Using Eclipse to add/update files to CVS

The command-line based CVS tool is hard to use for first time users; many GUI-based CVS tools are not really well designed to be easy to use either. I’m not against the point that developers and testers should learn how to use a technical tool in no time even though the tool is hard to use, but developers and testers have their schedules and need to be efficient. Having an efficient way to add and update files to CVS is very necessary. Eclipse is the tool I use to deal with CVS file operations. It works really well not only … Continue reading Using Eclipse to add/update files to CVS