Skip to content

Commit

Permalink
* Spec'd out Classist a little. RCov is misleading, it's functionalit…
Browse files Browse the repository at this point in the history
…y and intent are nearly completely unspec'd

* Fixed up Classist to not run the hook twice
  • Loading branch information
ELLIOTTCABLE committed Apr 12, 2008
1 parent ca240e5 commit f2b23e5
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 19 deletions.
33 changes: 33 additions & 0 deletions bugs/issue-35d8184c5e30b4af30bde4c3fb26318510e9270e.yaml
@@ -0,0 +1,33 @@
--- !ditz.rubyforge.org,2008-03-06/issue
title: Spec out Classist
desc: "The Classist module is currently completely unspec'd. Remedy this d-:"
type: :bugfix
component: API
release: 0 (stable API)
reporter: elliottcable <git@elliottcable.name>
status: :paused
disposition:
creation_time: 2008-04-12 08:30:55.286464 Z
references: []

id: 35d8184c5e30b4af30bde4c3fb26318510e9270e
log_events:
- - 2008-04-12 08:30:59.336422 Z
- elliottcable <git@elliottcable.name>
- created
- ""
- - 2008-04-12 08:47:43.331125 Z
- elliottcable <git@elliottcable.name>
- changed status from unstarted to in_progress
- Specc'ing on classist now. Ugh, always hard to spec intent instead of implementation with metacode... >,<
- - 2008-04-12 08:51:46.354367 Z
- elliottcable <git@elliottcable.name>
- changed status from in_progress to paused
- "Ugh, ran into a problem. Opening a ticket for it, and switching to work on said ticket. See #api-3"
- - 2008-04-12 10:35:20.793278 Z
- elliottcable <git@elliottcable.name>
- commented
- |-
Having trouble figuring out a way to hook into anonymous class creation. See this RCR, and the following discussion list thread:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/44249
http://readlist.com/lists/ruby-lang.org/ruby-talk/2/12138.html
26 changes: 26 additions & 0 deletions bugs/issue-7ceb27c31f2e272769862ab1ade77535722bf3d6.yaml
@@ -0,0 +1,26 @@
--- !ditz.rubyforge.org,2008-03-06/issue
title: Classist is running the ::classize method twice for every class init
desc: For some reason, any code in self.classize on a module including Classist is being run twice, instead of once, on class creation.
type: :bugfix
component: API
release: 0 (stable API)
reporter: elliottcable <git@elliottcable.name>
status: :closed
disposition: :fixed
creation_time: 2008-04-12 09:10:18.854263 Z
references: []

id: 7ceb27c31f2e272769862ab1ade77535722bf3d6
log_events:
- - 2008-04-12 09:10:30.911937 Z
- elliottcable <git@elliottcable.name>
- created
- ""
- - 2008-04-12 09:10:50.320112 Z
- elliottcable <git@elliottcable.name>
- changed status from unstarted to in_progress
- Going to try to fix this. Time to learn how to use ruby-debug!
- - 2008-04-12 10:33:13.837584 Z
- elliottcable <git@elliottcable.name>
- closed issue with disposition fixed
- Was pushing the first ancestor onto the array twice, changed to .shift to fix that
18 changes: 18 additions & 0 deletions bugs/issue-7d985968323a500e8a90e7c8d6d16e483d3356c1.yaml
@@ -0,0 +1,18 @@
--- !ditz.rubyforge.org,2008-03-06/issue
title: Fix RDie::System::classize's S constant setting
desc: Classize is currently setting the S constant to the class itself, not to newly created instances of the new class.
type: :bugfix
component: API
release: 0 (stable API)
reporter: elliottcable <git@elliottcable.name>
status: :unstarted
disposition:
creation_time: 2008-04-12 08:29:33.915160 Z
references: []

id: 7d985968323a500e8a90e7c8d6d16e483d3356c1
log_events:
- - 2008-04-12 08:30:03.244220 Z
- elliottcable <git@elliottcable.name>
- created
- This is rather critical, because I expect to be able to tell Sysdevs they can use 'S.' as a shortcut for 'self.'.
22 changes: 22 additions & 0 deletions bugs/issue-b58baf11104371b8d78b353f098de133df6ee94e.yaml
@@ -0,0 +1,22 @@
--- !ditz.rubyforge.org,2008-03-06/issue
title: Spec out Attrist
desc: Attrist is completely unrepresented in the specs, it isn't even recorded in rcov. Write some!
type: :bugfix
component: API
release: 0 (stable API)
reporter: elliottcable <git@elliottcable.name>
status: :unstarted
disposition:
creation_time: 2008-04-12 10:36:13.364030 Z
references: []

id: b58baf11104371b8d78b353f098de133df6ee94e
log_events:
- - 2008-04-12 10:36:16.030004 Z
- elliottcable <git@elliottcable.name>
- created
- ""
- - 2008-04-12 10:36:44.099365 Z
- elliottcable <git@elliottcable.name>
- changed title
- ""
39 changes: 20 additions & 19 deletions lib/classist.rb
@@ -1,27 +1,28 @@
module Classist

class ::Object
def self.inherited(klass)
return if klass.name == ''
ancestors = klass.name.split('::')

ancestors = ancestors.inject([Object.send(:const_get, ancestors.shift)]) do |acc, ancestor|
acc << acc.last.send(:const_get, ancestor)
end

classies = ancestors.reject{|a| !a.include? Classist}
classies.each do |classy|
classy.class_eval do
classize(klass)
end
end
nil
end
end

##
# When included into a module or class Foo, this will cause any classes defined
# within Foo to run the method Foo.classize(the_new_class). This module is
# no more than a sort of placeholder, all the real magic happens in
# Object.inherited.
# TODO: Figure out a way to do this, without messing with Object
end

class Object
def self.inherited(klass)
return if klass.name == ''
ancestors = klass.name.split('::')

ancestors = ancestors.inject([Object.send(:const_get, ancestors.first)]) do |acc, ancestor|
acc << acc.last.send(:const_get, ancestor)
end

classies = ancestors.reject{|a| !a.include? Classist}
classies.each do |classy|
classy.class_eval do
classize(klass)
end
end
nil
end
end
51 changes: 51 additions & 0 deletions spec/lib/classist_spec.rb
@@ -0,0 +1,51 @@
require File.join( File.dirname(__FILE__), "..", "spec_helper" )
require 'classist'

describe Classist do
before(:all) do
@spec_helper = lambda do
module ClassistSpecHelper
include Classist

Classized = []
def self.classize(klass)
Classized << klass
end
end
end
end
before(:each) do
@spec_helper.call
end

it "should allow the attachment of functionality to syntactically sugary class creation" do
module ClassistSpecHelper
class Foo; end
class Bar; end
end

ClassistSpecHelper::Classized.should == [
ClassistSpecHelper::Foo,
ClassistSpecHelper::Bar]
end

it "should allow the attachment of functionality to anonymous class creation" do
# May not be possible, as anonymous methods (by definition) have no name
# to work with when created, and thus when our hook would be run.

module ClassistSpecHelper
Foo = Class.new
Bar = Class.new
end

# ClassistSpecHelper::Classized.should == [
# ClassistSpecHelper::Foo,
# ClassistSpecHelper::Bar]

pending
end

after(:each) do
Object.send(:remove_const, :ClassistSpecHelper)
end
end

0 comments on commit f2b23e5

Please sign in to comment.