Ruby Gem Contributions

mongoid_touch

I like the .touch method of ActiveRecord, but didn't found the same tool for Mongoid.

So I build my own tiny extension to mongoid, wrapped it in a gem and published it.

Now everybody can touch a mongoid model instance, hooray!

Installation

On a shell: gem install mongoid_touch

In Gemfile: gem "mongoid_touch"

Usage

class MyModel
  include Mongoid::Document
  include Mongoid::Timestamps

  field :name, type: String
  field :modified_at, type: Time
end

mm = MyModel.create(name: "Mein Mongoid Model")
# this set timestamps for 'created_at' and 'updated_at'

# ... later in your code ...

mm.touch
# this set the 'updated_at' to the current Time

# also possible:
mm.touch(:modified_at)
# will update the 'modified_at' timestamp

# love exclamation marks to show instant persistance actions?
# friend of exception handling?
mm.touch!
# .touch, but with exceptions

The code is small, the addition is tiny, but it maybe saves a lot of time for poking around this cool feature.

Links

testrocket #1

First I added some code to the origin testrocket gem freshly created by PeterC.

This gem has its fountainhead in this CodeBrawl contest and was the winner of it.

I liked the idea and added some extra rockets -- we have four unary operators, so why not utilize the other two, too?

How to use

Install it with gem install testrocket or put in your Gemfile: gem "testrocket"

Then write your tests:

+-> { true }  # +-> for test which should pass
--> { false } # --> for test which should fail

Links

testrocket #2

But not enough for me:

So I added some extra markup to testrocket.

Unfortunatelly, Peter didn't liked it yet. So my launcher base has to be published in another way.

Solution: I created a further gem named "aki-testrocket".

Installation

Nearly the same way like the origin one, but:

In a shell: gem install aki-testrocket

In Gemfile: gem "aki-testrocket"

If you need to "require" it: require "testrocket" (yes, it is the same name like the origin!)

To use the launcher extension: require "testrocket/launcher"

Usage

launcher "my test package" do
  fire "my test section" do
    +-> { test.one == 1 }
    --> { test.two == 1 }
  end
end

Links