Project

cat

0.0
No commit activity in last 3 years
No release in over 3 years
Create objects in a sandbox
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Development

>= 0
>= 0
 Project Readme

cat¶ ↑

Create objects in a sandbox

This project grew out of a project where I needed to create complicated object definitions and didn't want to write it out in classic ruby syntax (clunky and fragile). So, this gem lets you easily generate classes inside a sandbox and clean it out the namespace between tests.

Build Status

Installation¶ ↑

gem install cat

Usage¶ ↑

require 'cat'

Creating classes¶ ↑

Add a single class

> Sandbox.add_class("Foo")
> Sandbox::Foo.new
 => #<Sandbox::Foo:0x007ff5a2829930>

Add a subclass

> Sandbox.add_class("Foo::Bar")
> Sandbox::Foo::Bar.new
 => #<Sandbox::Foo::Bar:0x007ff5a281f098>

Add some attributes to a class

> Sandbox.add_attributes("Foo::Bar", "id", :title)
> fb = Sandbox::Foo::Bar.new(id: 10, title: "I like chicken") # it adds an initialize method for you too
> fb.id
 => 10
> fb.title
 => "I like chicken"

Add a method to a class

> Sandbox.add_method("Foo::Bar", :food, lambda{"I like liver"})
> fb = Sandbox::Foo::Bar.new
> fb.food
 => "I like liver"

Or do it with a block

> Sandbox.add_method("Foo::Bar", :food) {"Meow mix meow mix"}
> fb = Sandbox::Foo::Bar.new
> fb.food
 => "Meow mix meow mix"

Class methods work the same way

> Sandbox.add_class_method("Foo::Bar", :babar, lambda{"king of elephants"})
> Sandbox::Foo::Bar.babar
 => "king of elephants"

When you've cluttered your namespace beyond repair, just delete it all

> Sandbox.cleanup!  # or of course, use the alias Sandbox.scoop! :)

Contributing to cat¶ ↑

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.

  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.

  • Fork the project.

  • Start a feature/bugfix branch.

  • Commit and push until you are happy with your contribution.

  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2012 Chris Doyle. See LICENSE.txt for further details.