put Document and DocumentResource into the Polecat namespace
This commit is contained in:
parent
b11090d145
commit
b9caf75d53
|
@ -1,6 +1,7 @@
|
|||
require 'polecat/document_resource'
|
||||
|
||||
module Document
|
||||
class Polecat
|
||||
module Document
|
||||
OPTIONS = {
|
||||
:index => true,
|
||||
:lazy => false,
|
||||
|
@ -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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
module DocumentResource
|
||||
class Polecat
|
||||
module DocumentResource
|
||||
def field name, options = {}
|
||||
attributes = self.instance_variable_get :@attributes
|
||||
attributes[name.to_sym] = Document::OPTIONS.merge(options)
|
||||
|
@ -32,4 +33,5 @@ module DocumentResource
|
|||
end
|
||||
RUBYCODE
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -27,7 +27,7 @@ end
|
|||
|
||||
module Spec
|
||||
class FooDocument
|
||||
include Document
|
||||
include Polecat::Document
|
||||
|
||||
field :id
|
||||
field :name, :lazy => true
|
||||
|
|
Loading…
Reference in New Issue