Skip to content

Commit

Permalink
First step to metaslots
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurii Rashkovskii committed May 14, 2008
1 parent b8eaa67 commit c3df40b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/strokedb/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def initialize(*args, &block)
# If slot was not found, it will return <tt>nil</tt>
#
def [](slotname)
slotname = slotname.document.uuid if slotname.is_a?(Meta) && slotname.is_a?(Module)
@slots[slotname.to_s].value rescue nil
end

Expand All @@ -212,6 +213,7 @@ def [](slotname)
# document[:slot_1] = "some value"
#
def []=(slotname, value)
slotname = slotname.document.uuid if slotname.is_a?(Meta) && slotname.is_a?(Module)
slotname = slotname.to_s

(@slots[slotname] ||= Slot.new(self, slotname)).value = value
Expand Down Expand Up @@ -282,7 +284,11 @@ def pretty_print #:nodoc:
if %w(version previous_version).member?(k) && v = self[k]
s << "#{k}: #{v[0,4]}..., "
else
s << "#{k}: #{self[k].inspect}, "
if k.match(/^#{UUID_RE}$/)
s << "[#{store.find(k).name}]: #{self[k].inspect}, " rescue s << "#{k}: #{self[k].inspect}, "
else
s << "#{k}: #{self[k].inspect}, "
end
end
end

Expand Down
24 changes: 24 additions & 0 deletions spec/lib/strokedb/document/metaslot_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require File.dirname(__FILE__) + '/spec_helper'

describe "Document" do

before(:each) do
setup_default_store
Object.send!(:remove_const,'SomeMeta') if defined?(SomeMeta)
SomeMeta = Meta.new
@document = Document.new
end

it "should assign a uuid-named slot for metaslot" do
@document[SomeMeta] = "some value"
@document.slotnames.should include(SomeMeta.document.uuid)
end

it "should be able to read metaslot" do
@document[SomeMeta] = "some value"
@document[SomeMeta].should == "some value"
end



end

0 comments on commit c3df40b

Please sign in to comment.