0
0
Fork 0

put Document and DocumentResource into the Polecat namespace

This commit is contained in:
Gibheer 2011-05-24 14:41:09 +02:00
parent b11090d145
commit b9caf75d53
6 changed files with 85 additions and 80 deletions

View File

@ -1,5 +1,6 @@
require 'polecat/document_resource'
class Polecat
module Document
OPTIONS = {
:index => true,
@ -46,9 +47,11 @@ module Document
end
end
# get all attributes
def attributes
return @attributes if @attributes
@attributes = Marshal.load(Marshal.dump(
self.class.instance_variable_get :@attributes))
end
end
end

View File

@ -1,3 +1,4 @@
class Polecat
module DocumentResource
def field name, options = {}
attributes = self.instance_variable_get :@attributes
@ -33,3 +34,4 @@ module DocumentResource
RUBYCODE
end
end
end

View File

@ -3,11 +3,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe "Document#attributes" do
it "returns a hash with all attributes" do
class FooDoc
include Document
include Polecat::Document
field :bar
end
d = FooDoc.new
d.attributes.should == {:bar => Document::OPTIONS}
d.attributes.should == {:bar => Polecat::Document::OPTIONS}
end
end

View File

@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe "DocumentRessource#field" do
it "creates a method to get an attribute value" do
class FooDoc
include Document
include Polecat::Document
field :doc
end
FooDoc.new.respond_to?(:doc).should == true
@ -11,7 +11,7 @@ describe "DocumentRessource#field" do
it "creates a method to set an attribute" do
class FooDoc
include Document
include Polecat::Document
field :doc
end
d = FooDoc.new

View File

@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe "Document#initialize" do
it "creates a new Document object" do
d = Spec::FooDocument.new
d.is_a?(Document).should == true
d.is_a?(Polecat::Document).should == true
end
it "takes a hash as argument" do

View File

@ -27,7 +27,7 @@ end
module Spec
class FooDocument
include Document
include Polecat::Document
field :id
field :name, :lazy => true