Skip to content

Commit

Permalink
Merge branch 'new-views' of git@github.com:yrashk/strokedb into new-v…
Browse files Browse the repository at this point in the history
…iews
  • Loading branch information
Oleg Andreev committed May 16, 2008
2 parents 7a35ee1 + 7e96025 commit 2e6c591
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/strokedb/document.rb
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
4 changes: 3 additions & 1 deletion lib/strokedb/document/meta.rb
Expand Up @@ -89,8 +89,10 @@ def uuid
end

def implements(another_meta)
values = @args.select{|a| a.is_a?(Hash) }.first
values = @args.find{|a| a.is_a?(Hash) }
values.merge!(another_meta.document.to_raw.delete_if {|k,v| ['name','uuid','version','previous_version','meta'].member?(k) })
values[:implements_metas] ||= []
values[:implements_metas] << another_meta.document
include(another_meta)
self
end
Expand Down
7 changes: 7 additions & 0 deletions spec/lib/strokedb/document/meta_spec.rb
Expand Up @@ -301,6 +301,10 @@ def implements_some_name_meta
ImplementsSomeName.name.should == "ImplementsSomeName"
end

it "should reference implemented meta" do
ImplementsSomeName.document.implements_metas.should == [SomeName.document]
end


end

Expand Down Expand Up @@ -362,6 +366,9 @@ def implements_some_name_meta
ImplementsSomeName.name.should == "ImplementsSomeName"
end

it "should reference implemented metas" do
ImplementsSomeName.document.implements_metas.to_set.should == [SomeName.document,SomeName1.document].to_set
end

end

Expand Down
38 changes: 38 additions & 0 deletions spec/lib/strokedb/document/metaslot_spec.rb
@@ -0,0 +1,38 @@
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

describe "with metaslot assigned, once saved and reloaded" do

before(:each) do
@document[SomeMeta] = "some value"
@document.save!
@document = @document.reload
end

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

end



end

0 comments on commit 2e6c591

Please sign in to comment.