module Polecat::Document
Constants
- OPTIONS
Public Class Methods
new(fields = {})
click to toggle source
creates a new document
It is possible to create a new document with a hash, which has all values of the fields. @example initializing a document
class Foo include Polecat::Document field :id field :description end f = Foo.new :id => 1, :description => 'foo'
# File lib/polecat/document.rb, line 32 def initialize fields = {} fields.each do |key, value| attribute_set key, value end end
Public Instance Methods
attribute_get(name)
click to toggle source
get an attribute of the document
# File lib/polecat/document.rb, line 39 def attribute_get name attributes[name.to_sym][:value] end
attribute_set(name, value)
click to toggle source
set an attribute of the document
# File lib/polecat/document.rb, line 44 def attribute_set name, value name = name.to_sym att = attributes if att.has_key? name att[name][:value] = value else raise ArgumentError, "attribute #{name} does not exist" end end
attributes()
click to toggle source
get all attributes
# File lib/polecat/document.rb, line 55 def attributes return @attributes if @attributes @attributes = Marshal.load(Marshal.dump( self.class.instance_variable_get :@attributes)) end