Posts for: #Ruby

How to install ruby-debug on Ruby 1.9

One of the major problem which prevent the migration to Ruby 1.9 is the lack of the porting of ruby-debug.

Here the steps I followed to made it working on my MacBook with Multiruby:


sudo gem install rake-compiler ruby_core_source --no-rdoc --no-ri
sudo gem install ruby-debug19 --no-rdoc --no-ri

I hope it works for you too!

[]

Memoria: Statistics for Redis

A couple of days ago I setup this blog with Redis as cache container, thanks to my Ruby gem: redis-store.

Now, following the old itch-your-own-scratches rule, I created a little Sinatra web application for Redis statistics: Memoria.

Memoria screenshot

# Getting Started

(sudo) gem install sinatra dm-core do_sqlite3 rspec
(sudo) gem install ezmobius-redis-rb jodosha-memoria -s http://gems.github.com
memoria /path/to/installation
cd /path/to/installation
cp memoria.yml.example memoria.yml
rackup config.ru --port 9292 mongrel

Memoria is still in an embryonic stage, feel free to suggest features.

[]

Hash deep search

I’m back and I wanna share those simple snippets with you:

~

class Hash def deep_has_key?(key) self.has_key?(key) || any? {|k, v| v.deep_has_key?(key) if v.is_a? Hash} end alias :deep_include? :deep_has_key? alias :deep_key? :deep_has_key? alias :deep_member? :deep_has_key?

def deep_has_value?(value) self.has_value?(value) || any? {|k,v| v.deep_has_value?(value) if v.is_a? Hash} end alias :deep_value? :deep_has_value? end

Example:
{:a => {:c => 'c'}, :b =>{:d => {:e => 'e'}}}.deep_has_key?(:e) # => true {:a => {:c => 'c'}, :b =>{:d => {:e => 'e'}}}.deep_has_key?(:z) # => false

{:a => {:c => ‘c’}, :b =>{:d => {:e => ’e’}}}.deep_has_value?(’e’) # => true {:a => {:c => ‘c’}, :b =>{:d => {:e => ’e’}}}.deep_has_value?(‘z’) # => false

[]

Skip Mocha

Yesterday I confessed how messed up was CachedModels 0.0.2. The problem was pretty simple: I made some mistakes mocking up Memcached behaviors.

The Dilemma

I massively use Mocha for track how many calls CachedModels performs against the cache, and (ideally) for run test suite without any server active. But, this approach led me to broken results. Should I keep out Mocha from my tests?

The Solution

Why don’t mock the mock? We know, Ruby allows to add behaviors to classes at runtime, Mocha itself take this advantage. I added to my test_helper.rb the following code:
if ENV['SKIP_MOCHA'] == 'true' class Object def expects(*args) self end

def method_missing(method_name, *args, &block)
end

end

[]

Released Sashimi 0.2.1

I’ve just released a new version of Sashimi (0.2.1), it fixes a bug for Ubuntu.

The Problem

When the script starts tries to load repository concerned classes: GitRepository and SvnRepository, which are subclasses of AbstractRepository. In repositories.rb I use Dir#[] to load all the .rb files in a certain directory, but the order of the resulting array is unpredictable, so if the first class was not AbstractRepository Sashimi was crashing.

The Solution

I’ve fixed it, so, if you have experienced this problem, please update Sashimi with:
$ (sudo) gem update sashimi

[]