obsidian 0.0.4 → 0.0.5

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.
@@ -1,3 +1,7 @@
1
+ 2008-10-30
2
+ * Added Object#try
3
+ * Added meta extensions from Why
4
+
1
5
  2008-04-11
2
6
  * Updated documentation in README
3
7
 
@@ -5,6 +5,8 @@ README.rdoc
5
5
  README.txt
6
6
  Rakefile
7
7
  lib/obsidian.rb
8
+ lib/obsidian/extensions/object.rb
9
+ lib/obsidian/extensions/try.rb
8
10
  lib/obsidian/rails/helper_test.rb
9
11
  lib/obsidian/rails/model_update_tracker.rb
10
12
  lib/obsidian/spec.rb
@@ -13,7 +15,9 @@ lib/obsidian/spec/set_spec_helper.rb
13
15
  obsidian.gemspec
14
16
  test/obsidian_test.rb
15
17
  test/test_helper.rb
18
+ test/units/obsidian/object_extensions_test.rb
16
19
  test/units/obsidian/rails/model_update_tracker_test.rb
17
20
  test/units/obsidian/spec/map_spec_helper_test.rb
18
21
  test/units/obsidian/spec/set_spec_helper_test.rb
19
22
  test/units/obsidian/spec_test.rb
23
+ test/units/obsidian/try_test.rb
data/Rakefile CHANGED
@@ -5,9 +5,6 @@ require 'rake/rdoctask'
5
5
  require 'hoe'
6
6
  require 'lib/obsidian'
7
7
 
8
- desc 'Default: run unit tests.'
9
- task :default => :test
10
-
11
8
  hoe = Hoe.new('obsidian', Obsidian::VERSION) do |p|
12
9
  p.rubyforge_name = "thinkrelevance"
13
10
  p.description = "It's metastable"
@@ -18,6 +15,7 @@ hoe = Hoe.new('obsidian', Obsidian::VERSION) do |p|
18
15
  p.email = "opensource@thinkrelevance.com"
19
16
  p.url = "http://opensource.thinkrelevance.com"
20
17
  p.rdoc_pattern = /^(lib|bin|ext)|txt|rdoc$/
18
+ p.test_globs = "test/**/*_test.rb"
21
19
  end
22
20
 
23
21
  # Override RDoc to use allison template, and also use our .rdoc README as the main page instead of the default README.txt
@@ -35,13 +33,6 @@ Rake::RDocTask.new(:docs) do |rd|
35
33
  title = "#{hoe.rubyforge_name}'s " + title if hoe.rubyforge_name != hoe.name
36
34
  end
37
35
 
38
- desc 'Test obsidian.'
39
- Rake::TestTask.new(:test) do |t|
40
- t.libs << 'lib'
41
- t.pattern = 'test/**/*_test.rb'
42
- t.verbose = true
43
- end
44
-
45
36
  begin
46
37
  require 'rcov'
47
38
  require "rcov/rcovtask"
@@ -72,3 +63,4 @@ rescue LoadError
72
63
  puts 'sudo gem install rcov # if you want the rcov tasks'
73
64
  end
74
65
  end
66
+
@@ -1,3 +1,3 @@
1
1
  module Obsidian
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -0,0 +1,31 @@
1
+ # Metaclass goodness thanks to why:
2
+ # see: http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html
3
+ module Obsidian
4
+ module Extensions
5
+ module Object
6
+ # The hidden singleton lurks behind everyone
7
+ def metaclass
8
+ class << self
9
+ self
10
+ end
11
+ end
12
+
13
+ def meta_eval &blk
14
+ metaclass.instance_eval &blk
15
+ end
16
+
17
+ # Adds methods to a metaclass
18
+ def meta_def name, &blk
19
+ meta_eval { define_method name, &blk }
20
+ end
21
+
22
+ # Defines an instance method within a class
23
+ def class_def name, &blk
24
+ class_eval { define_method name, &blk }
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+
31
+ Object.class_eval { include Obsidian::Extensions::Object }
@@ -0,0 +1,16 @@
1
+ module Obsidian
2
+ module Extensions
3
+ module Try
4
+ # Instead of
5
+ # @person ? @person.name : nil
6
+ # Use try:
7
+ # @person.try(:name)
8
+ def try(method)
9
+ send method if respond_to? method
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+
16
+ Object.class_eval { include Obsidian::Extensions::Try }
@@ -1,34 +1,36 @@
1
- (in /Users/rsanheim/src/relevance/runcoderun/vendor/gems/obsidian-0.0.4)
1
+ (in /Users/rsanheim/src/relevance/obsidian)
2
+ # -*- encoding: utf-8 -*-
3
+
2
4
  Gem::Specification.new do |s|
3
5
  s.name = %q{obsidian}
4
- s.version = "0.0.4"
6
+ s.version = "0.0.5"
5
7
 
6
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
7
9
  s.authors = ["Relevance"]
8
- s.date = %q{2008-07-09}
10
+ s.date = %q{2008-10-30}
9
11
  s.description = %q{It's metastable}
10
12
  s.email = %q{opensource@thinkrelevance.com}
11
13
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
12
- s.files = ["History.txt", "LICENSE", "Manifest.txt", "README.rdoc", "README.txt", "Rakefile", "lib/obsidian.rb", "lib/obsidian/rails/helper_test.rb", "lib/obsidian/rails/model_update_tracker.rb", "lib/obsidian/spec.rb", "lib/obsidian/spec/map_spec_helper.rb", "lib/obsidian/spec/set_spec_helper.rb", "test/obsidian_test.rb", "test/test_helper.rb", "test/units/obsidian/rails/model_update_tracker_test.rb", "test/units/obsidian/spec/map_spec_helper_test.rb", "test/units/obsidian/spec/set_spec_helper_test.rb", "test/units/obsidian/spec_test.rb"]
14
+ s.files = ["History.txt", "LICENSE", "Manifest.txt", "README.rdoc", "README.txt", "Rakefile", "lib/obsidian.rb", "lib/obsidian/rails/helper_test.rb", "lib/obsidian/rails/model_update_tracker.rb", "lib/obsidian/spec.rb", "lib/obsidian/spec/map_spec_helper.rb", "lib/obsidian/spec/set_spec_helper.rb", "obsidian.gemspec", "test/obsidian_test.rb", "test/test_helper.rb", "test/units/obsidian/rails/model_update_tracker_test.rb", "test/units/obsidian/spec/map_spec_helper_test.rb", "test/units/obsidian/spec/set_spec_helper_test.rb", "test/units/obsidian/spec_test.rb", "test/units/obsidian/object_extensions_test.rb", "test/units/obsidian/try_test.rb"]
13
15
  s.has_rdoc = true
14
16
  s.homepage = %q{http://opensource.thinkrelevance.com}
15
17
  s.rdoc_options = ["--main", "README.txt"]
16
18
  s.require_paths = ["lib"]
17
19
  s.rubyforge_project = %q{thinkrelevance}
18
- s.rubygems_version = %q{1.2.0}
20
+ s.rubygems_version = %q{1.3.0}
19
21
  s.summary = %q{It's metastable}
20
- s.test_files = ["test/test_helper.rb"]
22
+ s.test_files = ["test/obsidian_test.rb", "test/units/obsidian/object_extensions_test.rb", "test/units/obsidian/rails/model_update_tracker_test.rb", "test/units/obsidian/spec/map_spec_helper_test.rb", "test/units/obsidian/spec/set_spec_helper_test.rb", "test/units/obsidian/spec_test.rb", "test/units/obsidian/try_test.rb"]
21
23
 
22
24
  if s.respond_to? :specification_version then
23
25
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
26
  s.specification_version = 2
25
27
 
26
- if current_version >= 3 then
27
- s.add_development_dependency(%q<hoe>, [">= 1.7.0"])
28
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
29
+ s.add_development_dependency(%q<hoe>, [">= 1.8.1"])
28
30
  else
29
- s.add_dependency(%q<hoe>, [">= 1.7.0"])
31
+ s.add_dependency(%q<hoe>, [">= 1.8.1"])
30
32
  end
31
33
  else
32
- s.add_dependency(%q<hoe>, [">= 1.7.0"])
34
+ s.add_dependency(%q<hoe>, [">= 1.8.1"])
33
35
  end
34
36
  end
@@ -10,5 +10,4 @@ require 'test/spec'
10
10
  require 'mocha'
11
11
  require 'ostruct'
12
12
  require 'activerecord'
13
- require 'obsidian'
14
-
13
+ require 'obsidian'
@@ -0,0 +1,29 @@
1
+ require File.join(File.dirname(__FILE__), "../..", "test_helper.rb")
2
+ require 'obsidian/extensions/object'
3
+
4
+ describe "object extensions" do
5
+ it "should get metaclass" do
6
+ obj = Object.new
7
+ metaklass = (class << obj; self; end;)
8
+ obj.metaclass.should == metaklass
9
+ end
10
+
11
+ it "should be able to add methods to the meta class" do
12
+ obj = Object.new
13
+ obj.meta_def(:speak) { "bark!" }
14
+ obj.should.respond_to :speak
15
+
16
+ another_obj = Object.new
17
+ another_obj.should.not.respond_to :speak
18
+ end
19
+
20
+ class Foo; end
21
+
22
+ it "should be able to define instance methods from the class" do
23
+ Foo.class_def(:hi) { "hello!" }
24
+ Foo.new.hi.should == "hello!"
25
+ Foo.should.not.respond_to :hi
26
+ end
27
+
28
+
29
+ end
@@ -26,7 +26,7 @@ describe "Obsidian::Spec find_calling_line" do
26
26
  it "can parse a stack trace to find the caller of a method" do
27
27
  file, line_no = nest_1("nest_1")
28
28
  file.should.match %r{spec_test.rb$}
29
- line_no.should.match /^\d+$/
29
+ line_no.should.match(/^\d+$/)
30
30
  end
31
31
  it "returns nil if a method does not exist" do
32
32
  file, line_no = nest_1("not_a_real_method_name")
@@ -43,7 +43,7 @@ describe "Obsidian::Spec read_calling_line" do
43
43
  nest_2(name)
44
44
  end
45
45
  it "can parse a stack trace to find the caller of a method" do
46
- nest_1("nest_1").should.match /nest_1\("nest_1"\)/
46
+ nest_1("nest_1").should.match(/nest_1\("nest_1"\)/)
47
47
  end
48
48
  it "returns nil if a method does not exist" do
49
49
  nest_1("not_a_real_method_name").should.be nil
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), "../..", "test_helper.rb")
2
+ require 'obsidian/extensions/try'
3
+
4
+ describe "try object extension" do
5
+
6
+ it "is equivalent to @foo ? @foo.meth : nil" do
7
+ ["my string", Array.new, nil].each do |val|
8
+ @foo = val
9
+ @foo.try(:length).should == (@foo ? @foo.length : nil)
10
+ end
11
+
12
+ end
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obsidian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Relevance
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-09 00:00:00 -04:00
12
+ date: 2008-10-30 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.7.0
23
+ version: 1.8.1
24
24
  version:
25
25
  description: It's metastable
26
26
  email: opensource@thinkrelevance.com
@@ -40,6 +40,8 @@ files:
40
40
  - README.txt
41
41
  - Rakefile
42
42
  - lib/obsidian.rb
43
+ - lib/obsidian/extensions/object.rb
44
+ - lib/obsidian/extensions/try.rb
43
45
  - lib/obsidian/rails/helper_test.rb
44
46
  - lib/obsidian/rails/model_update_tracker.rb
45
47
  - lib/obsidian/spec.rb
@@ -48,10 +50,12 @@ files:
48
50
  - obsidian.gemspec
49
51
  - test/obsidian_test.rb
50
52
  - test/test_helper.rb
53
+ - test/units/obsidian/object_extensions_test.rb
51
54
  - test/units/obsidian/rails/model_update_tracker_test.rb
52
55
  - test/units/obsidian/spec/map_spec_helper_test.rb
53
56
  - test/units/obsidian/spec/set_spec_helper_test.rb
54
57
  - test/units/obsidian/spec_test.rb
58
+ - test/units/obsidian/try_test.rb
55
59
  has_rdoc: true
56
60
  homepage: http://opensource.thinkrelevance.com
57
61
  post_install_message:
@@ -75,9 +79,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
79
  requirements: []
76
80
 
77
81
  rubyforge_project: thinkrelevance
78
- rubygems_version: 1.2.0
82
+ rubygems_version: 1.3.0
79
83
  signing_key:
80
84
  specification_version: 2
81
85
  summary: It's metastable
82
86
  test_files:
83
- - test/test_helper.rb
87
+ - test/obsidian_test.rb
88
+ - test/units/obsidian/object_extensions_test.rb
89
+ - test/units/obsidian/rails/model_update_tracker_test.rb
90
+ - test/units/obsidian/spec/map_spec_helper_test.rb
91
+ - test/units/obsidian/spec/set_spec_helper_test.rb
92
+ - test/units/obsidian/spec_test.rb
93
+ - test/units/obsidian/try_test.rb