cat 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby-18mode
7
+ - jruby-19mode
8
+ - rbx-18mode
9
+ - rbx-19mode
10
+ - ree
@@ -1,6 +1,67 @@
1
1
  = cat
2
2
 
3
- Description goes here.
3
+ Create objects in a sandbox
4
+
5
+ This project grew out of a project where I needed to create complicated object definitions and didn't
6
+ want to write it out in classic ruby syntax (clunky and fragile). So, this gem lets you easily generate
7
+ classes inside a sandbox and clean it out the namespace between tests.
8
+
9
+ {<img src="https://secure.travis-ci.org/arches/cat.png?branch=master" alt="Build Status" />}[http://travis-ci.org/arches/cat]
10
+
11
+ == Installation
12
+
13
+ gem install cat
14
+
15
+ == Usage
16
+
17
+ require 'cat'
18
+
19
+ === Creating classes
20
+
21
+ Add a single class
22
+
23
+ > Sandbox.add_class("Foo")
24
+ > Sandbox::Foo.new
25
+ => #<Sandbox::Foo:0x007ff5a2829930>
26
+
27
+ Add a subclass
28
+
29
+ > Sandbox.add_class("Foo::Bar")
30
+ > Sandbox::Foo::Bar.new
31
+ => #<Sandbox::Foo::Bar:0x007ff5a281f098>
32
+
33
+ Add some attributes to a class
34
+
35
+ > Sandbox.add_attributes("Foo::Bar", "id", :title)
36
+ > fb = Sandbox::Foo::Bar.new(id: 10, title: "I like chicken") # it adds an initialize method for you too
37
+ > fb.id
38
+ => 10
39
+ > fb.title
40
+ => "I like chicken"
41
+
42
+ Add a method to a class
43
+
44
+ > Sandbox.add_method("Foo::Bar", :food, lambda{"I like liver"})
45
+ > fb = Sandbox::Foo::Bar.new
46
+ > fb.food
47
+ => "I like liver"
48
+
49
+ Or do it with a block
50
+
51
+ > Sandbox.add_method("Foo::Bar", :food) {"Meow mix meow mix"}
52
+ > fb = Sandbox::Foo::Bar.new
53
+ > fb.food
54
+ => "Meow mix meow mix"
55
+
56
+ Class methods work the same way
57
+
58
+ > Sandbox.add_class_method("Foo::Bar", :babar, lambda{"king of elephants"})
59
+ > Sandbox::Foo::Bar.babar
60
+ => "king of elephants"
61
+
62
+ When you've cluttered your namespace beyond repair, just delete it all
63
+
64
+ > Sandbox.cleanup! # or of course, use the alias Sandbox.scoop! :)
4
65
 
5
66
  == Contributing to cat
6
67
 
data/Rakefile CHANGED
@@ -25,14 +25,14 @@ Jeweler::Tasks.new do |gem|
25
25
  end
26
26
  Jeweler::RubygemsDotOrgTasks.new
27
27
 
28
- require 'rake/testtask'
29
- Rake::TestTask.new(:test) do |test|
30
- test.libs << 'lib' << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
28
+ require 'rspec/core/rake_task'
29
+
30
+ desc "Run specs"
31
+ RSpec::Core::RakeTask.new do |t|
33
32
  end
34
33
 
35
- task :default => :test
34
+
35
+ task :default => :spec
36
36
 
37
37
  require 'rdoc/task'
38
38
  Rake::RDocTask.new do |rdoc|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "cat"
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chris Doyle"]
12
- s.date = "2012-04-04"
12
+ s.date = "2012-04-27"
13
13
  s.description = "Create objects in a sandbox"
14
14
  s.email = "archslide@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.files = [
20
20
  ".document",
21
21
  ".rvmrc",
22
+ ".travis.yml",
22
23
  "Gemfile",
23
24
  "Gemfile.lock",
24
25
  "LICENSE.txt",
@@ -13,9 +13,11 @@ module Sandbox
13
13
  attr_accessor *attrs
14
14
 
15
15
  # set up the 'initialize' method to assign the attributes
16
- define_method(:initialize) do |value_hash={}|
17
- attrs.each_with_index do |attr|
18
- instance_variable_set("@#{attr}", value_hash[attr.to_sym])
16
+ define_method(:initialize) do |*value_hash|
17
+ value_hash = value_hash.first
18
+ value_hash ||= {}
19
+ value_hash.each do |k, v|
20
+ instance_variable_set("@#{k.to_s}", v)
19
21
  end
20
22
  end
21
23
  end
@@ -50,7 +52,7 @@ module Sandbox
50
52
  def self.const_set_from_string(delimited_klasses)
51
53
  # try to const_get before set const_set to avoid "already initialized" warnings
52
54
  delimited_klasses.split("::").inject(self) do |const, klass|
53
- const.constants.include?(klass.to_sym) ? const.const_get(klass) : const.const_set(klass, Class.new)
55
+ const.constants.collect(&:to_s).include?(klass.to_s) ? const.const_get(klass) : const.const_set(klass, Class.new)
54
56
  end
55
57
 
56
58
  @@created_classes << delimited_klasses.split("::").first
@@ -1,4 +1,4 @@
1
- require_relative '../lib/sandbox'
1
+ require 'sandbox'
2
2
 
3
3
  describe Sandbox do
4
4
 
@@ -12,7 +12,7 @@ describe Sandbox do
12
12
  Sandbox.add_class("Foo")
13
13
  constants = Sandbox.created_classes
14
14
  Sandbox.cleanup!
15
- Sandbox.created_classes.should == ["Foo"]
15
+ Sandbox.created_classes.collect(&:to_s).should == ["Foo"]
16
16
  constants.each do |const|
17
17
  Sandbox.constants.should_not include(const)
18
18
  end
@@ -22,14 +22,14 @@ describe Sandbox do
22
22
  describe "#add_class" do
23
23
  it "creates a class namedspaced under Sandbox" do
24
24
  Sandbox.add_class("Foo")
25
- Sandbox.constants.should include(:Foo)
25
+ Sandbox.constants.collect(&:to_s).should include("Foo")
26
26
  end
27
27
 
28
28
  describe "when you pass a double-colon delimited string" do
29
29
  it "creates nested subclasses" do
30
30
  Sandbox.add_class("Bar::Wood")
31
- Sandbox.constants.should include(:Bar)
32
- Sandbox::Bar.constants.should include(:Wood)
31
+ Sandbox.constants.collect(&:to_s).should include("Bar")
32
+ Sandbox::Bar.constants.collect(&:to_s).should include("Wood")
33
33
  end
34
34
  end
35
35
  end
@@ -49,7 +49,7 @@ describe Sandbox do
49
49
  it "adds an initialize method to set attributes with a hash" do
50
50
  Sandbox.add_class("Soap::Ivory::Powdered")
51
51
  Sandbox.add_attributes("Soap::Ivory", "id", :title)
52
- ivory = Sandbox::Soap::Ivory.new(id: 10, title: "Toweling off")
52
+ ivory = Sandbox::Soap::Ivory.new(:id => 10, :title => "Toweling off")
53
53
 
54
54
  ivory.id.should == 10
55
55
  ivory.title.should == "Toweling off"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-04 00:00:00.000000000 Z
12
+ date: 2012-04-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -85,6 +85,7 @@ extra_rdoc_files:
85
85
  files:
86
86
  - .document
87
87
  - .rvmrc
88
+ - .travis.yml
88
89
  - Gemfile
89
90
  - Gemfile.lock
90
91
  - LICENSE.txt
@@ -110,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
111
  version: '0'
111
112
  segments:
112
113
  - 0
113
- hash: 2974900436173929075
114
+ hash: 1185247395237564071
114
115
  required_rubygems_version: !ruby/object:Gem::Requirement
115
116
  none: false
116
117
  requirements: