cat 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p125@cat"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.10.3" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | grep -vE '^Using|Your bundle is complete'
48
+ # fi
data/Gemfile CHANGED
@@ -1,11 +1,7 @@
1
1
  source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
2
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
3
  group :development do
4
+ gem "rspec"
9
5
  gem "rdoc"
10
6
  gem "bundler"
11
7
  gem "jeweler"
@@ -1,6 +1,7 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ diff-lcs (1.1.3)
4
5
  git (1.2.5)
5
6
  jeweler (1.8.3)
6
7
  bundler (~> 1.0)
@@ -11,6 +12,14 @@ GEM
11
12
  rake (0.9.2.2)
12
13
  rdoc (3.12)
13
14
  json (~> 1.4)
15
+ rspec (2.9.0)
16
+ rspec-core (~> 2.9.0)
17
+ rspec-expectations (~> 2.9.0)
18
+ rspec-mocks (~> 2.9.0)
19
+ rspec-core (2.9.0)
20
+ rspec-expectations (2.9.1)
21
+ diff-lcs (~> 1.1.3)
22
+ rspec-mocks (2.9.0)
14
23
 
15
24
  PLATFORMS
16
25
  ruby
@@ -19,3 +28,4 @@ DEPENDENCIES
19
28
  bundler
20
29
  jeweler
21
30
  rdoc
31
+ rspec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "cat"
8
- s.version = "0.0.0"
8
+ s.version = "0.1.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-03"
12
+ s.date = "2012-04-04"
13
13
  s.description = "...like a cat"
14
14
  s.email = "archslide@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
+ ".rvmrc",
21
22
  "Gemfile",
22
23
  "Gemfile.lock",
23
24
  "LICENSE.txt",
@@ -26,8 +27,8 @@ Gem::Specification.new do |s|
26
27
  "VERSION",
27
28
  "cat.gemspec",
28
29
  "lib/cat.rb",
29
- "test/helper.rb",
30
- "test/test_cat.rb"
30
+ "lib/sandbox.rb",
31
+ "spec/cat_spec.rb"
31
32
  ]
32
33
  s.homepage = "http://github.com/arches/cat"
33
34
  s.licenses = ["MIT"]
@@ -39,15 +40,18 @@ Gem::Specification.new do |s|
39
40
  s.specification_version = 3
40
41
 
41
42
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_development_dependency(%q<rspec>, [">= 0"])
42
44
  s.add_development_dependency(%q<rdoc>, [">= 0"])
43
45
  s.add_development_dependency(%q<bundler>, [">= 0"])
44
46
  s.add_development_dependency(%q<jeweler>, [">= 0"])
45
47
  else
48
+ s.add_dependency(%q<rspec>, [">= 0"])
46
49
  s.add_dependency(%q<rdoc>, [">= 0"])
47
50
  s.add_dependency(%q<bundler>, [">= 0"])
48
51
  s.add_dependency(%q<jeweler>, [">= 0"])
49
52
  end
50
53
  else
54
+ s.add_dependency(%q<rspec>, [">= 0"])
51
55
  s.add_dependency(%q<rdoc>, [">= 0"])
52
56
  s.add_dependency(%q<bundler>, [">= 0"])
53
57
  s.add_dependency(%q<jeweler>, [">= 0"])
data/lib/cat.rb CHANGED
@@ -0,0 +1 @@
1
+ require_relative './sandbox'
@@ -0,0 +1,59 @@
1
+ module Sandbox
2
+
3
+ # keep track of the top-level classes we create, so we can destroy only those methods
4
+ # if we get mixed in somewhere
5
+ @@created_classes = []
6
+
7
+ def self.add_class(klass)
8
+ const_set_from_string(klass)
9
+ end
10
+
11
+ def self.add_attributes(klass, *attrs)
12
+ self.const_get_from_string(klass).class_eval do
13
+ attr_accessor *attrs
14
+
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])
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ def self.add_method(klass, method_name, proc_obj=nil, &blk)
25
+ self.const_get_from_string(klass).send(:define_method, method_name, proc_obj || blk)
26
+ end
27
+
28
+ def self.add_class_method(klass, method_name, proc_obj=nil, &blk)
29
+ singleton = (
30
+ class << self.const_get_from_string(klass); self end)
31
+ singleton.send(:define_method, method_name, proc_obj || blk)
32
+ end
33
+
34
+ def self.cleanup!
35
+ constants.each { |klass| remove_const klass }
36
+ end
37
+
38
+ def self.scoop!
39
+ self.cleanup!
40
+ end
41
+
42
+ def self.created_classes
43
+ @@created_classes
44
+ end
45
+
46
+ def self.const_get_from_string(klass)
47
+ klass.split("::").inject(self) { |const, klass| const.const_get(klass) }
48
+ end
49
+
50
+ def self.const_set_from_string(delimited_klasses)
51
+ # try to const_get before set const_set to avoid "already initialized" warnings
52
+ 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)
54
+ end
55
+
56
+ @@created_classes << delimited_klasses.split("::").first
57
+ @@created_classes.uniq!
58
+ end
59
+ end
@@ -0,0 +1,114 @@
1
+ require_relative '../lib/sandbox'
2
+
3
+ describe Sandbox do
4
+
5
+ before(:each) do
6
+ Sandbox.cleanup!
7
+ Sandbox.constants.should == []
8
+ end
9
+
10
+ describe "#cleanup!" do
11
+ it "removes all the classes defined by Sandbox" do
12
+ Sandbox.add_class("Foo")
13
+ constants = Sandbox.created_classes
14
+ Sandbox.cleanup!
15
+ Sandbox.created_classes.should == ["Foo"]
16
+ constants.each do |const|
17
+ Sandbox.constants.should_not include(const)
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "#add_class" do
23
+ it "creates a class namedspaced under Sandbox" do
24
+ Sandbox.add_class("Foo")
25
+ Sandbox.constants.should include(:Foo)
26
+ end
27
+
28
+ describe "when you pass a double-colon delimited string" do
29
+ it "creates nested subclasses" do
30
+ Sandbox.add_class("Bar::Wood")
31
+ Sandbox.constants.should include(:Bar)
32
+ Sandbox::Bar.constants.should include(:Wood)
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "#add_attributes" do
38
+ it "adds getter and setter methods to the class" do
39
+ Sandbox.add_class("Soap::Ivory::Powdered")
40
+ Sandbox.add_attributes("Soap::Ivory", "id", :title)
41
+ ivory = Sandbox::Soap::Ivory.new
42
+ ivory.id = 10
43
+ ivory.title = "Toweling off"
44
+
45
+ ivory.id.should == 10
46
+ ivory.title.should == "Toweling off"
47
+ end
48
+
49
+ it "adds an initialize method to set attributes with a hash" do
50
+ Sandbox.add_class("Soap::Ivory::Powdered")
51
+ Sandbox.add_attributes("Soap::Ivory", "id", :title)
52
+ ivory = Sandbox::Soap::Ivory.new(id: 10, title: "Toweling off")
53
+
54
+ ivory.id.should == 10
55
+ ivory.title.should == "Toweling off"
56
+ end
57
+ end
58
+
59
+ describe "#add_method" do
60
+ context "passing a proc" do
61
+ it "adds an instance method" do
62
+ Sandbox.add_class("Soap::Ivory::Liquid")
63
+ Sandbox.add_method("Soap::Ivory", :imbroglio, lambda { 'he said she said' })
64
+
65
+ ivory = Sandbox::Soap::Ivory.new
66
+ ivory.imbroglio.should == 'he said she said'
67
+ end
68
+ end
69
+
70
+ context "passing a block" do
71
+ it "adds an instance method" do
72
+ Sandbox.add_class("Soap::Ivory::Liquid")
73
+ Sandbox.add_method("Soap::Ivory", :imbroglio) { 'he said she said' }
74
+
75
+ ivory = Sandbox::Soap::Ivory.new
76
+ ivory.imbroglio.should == 'he said she said'
77
+ end
78
+ end
79
+ end
80
+
81
+ describe "#add_class_method" do
82
+ context "passing a proc" do
83
+ it "adds a class method" do
84
+ Sandbox.add_class("Foo")
85
+ Sandbox.add_class_method("Foo", "bar", lambda { "foo foo" })
86
+
87
+ Sandbox::Foo.bar.should == "foo foo"
88
+ end
89
+ end
90
+
91
+ context "passing a block" do
92
+ it "adds a class method" do
93
+ Sandbox.add_class("Foo")
94
+ Sandbox.add_class_method("Foo", "bar") { "foo " * 2 }
95
+
96
+ Sandbox::Foo.bar.should == "foo foo "
97
+ end
98
+ end
99
+ end
100
+
101
+ describe "setting a subclass on an existing subclass" do
102
+ it "doesn't raise a warning" do
103
+ orig_stderr = $stderr
104
+ $stderr = StringIO.new
105
+
106
+ Sandbox.add_class("Foo::Bar")
107
+ Sandbox.add_class("Foo::Babar")
108
+
109
+ $stderr.rewind
110
+ $stderr.string.chomp.should == ""
111
+ $stderr = orig_stderr
112
+ end
113
+ end
114
+ end
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.0.0
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-03 00:00:00.000000000 Z
12
+ date: 2012-04-04 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: rdoc
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -68,6 +84,7 @@ extra_rdoc_files:
68
84
  - README.rdoc
69
85
  files:
70
86
  - .document
87
+ - .rvmrc
71
88
  - Gemfile
72
89
  - Gemfile.lock
73
90
  - LICENSE.txt
@@ -76,8 +93,8 @@ files:
76
93
  - VERSION
77
94
  - cat.gemspec
78
95
  - lib/cat.rb
79
- - test/helper.rb
80
- - test/test_cat.rb
96
+ - lib/sandbox.rb
97
+ - spec/cat_spec.rb
81
98
  homepage: http://github.com/arches/cat
82
99
  licenses:
83
100
  - MIT
@@ -93,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
110
  version: '0'
94
111
  segments:
95
112
  - 0
96
- hash: 1413869309127843363
113
+ hash: 1364610243826607504
97
114
  required_rubygems_version: !ruby/object:Gem::Requirement
98
115
  none: false
99
116
  requirements:
@@ -1,18 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'test/unit'
11
- require 'shoulda'
12
-
13
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- $LOAD_PATH.unshift(File.dirname(__FILE__))
15
- require 'cat'
16
-
17
- class Test::Unit::TestCase
18
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestCat < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end