Module: Exegesis

Extended by:
Exegesis
Included in:
Exegesis
Defined in:
lib/exegesis.rb,
lib/exegesis/model.rb,
lib/exegesis/design.rb,
lib/exegesis/server.rb,
lib/exegesis/database.rb,
lib/exegesis/document.rb,
lib/exegesis/utils/http.rb,
lib/exegesis/document/attachment.rb,
lib/exegesis/document/collection.rb,
lib/exegesis/document/attachments.rb,
lib/exegesis/document/generic_document.rb

Defined Under Namespace

Modules: Database, Document, Http, Model Classes: Design, DocumentCollection, GenericDocument, Server

Instance Method Summary collapse

Instance Method Details

#constantize(camel_cased_word) ⇒ Object

extracted from Extlib

Constantize tries to find a declared constant with the name specified in the string. It raises a NameError when the name is not in CamelCase or is not initialized.

“Module”.constantize #=> Module “Class”.constantize #=> Class



38
39
40
41
42
43
44
45
# File 'lib/exegesis.rb', line 38

def constantize(camel_cased_word)
  return Exegesis::GenericDocument if camel_cased_word.nil?
  unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word
    raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!"
  end

  Object.module_eval("::#{$1}", __FILE__, __LINE__)
end

#instantiate(doc, database) ⇒ Object



47
48
49
50
51
# File 'lib/exegesis.rb', line 47

def instantiate(doc, database)
  doc = constantize(doc['class']).new(doc)
  doc.database = database if doc.respond_to?(:database=)
  doc
end

#model_classesObject



25
26
27
# File 'lib/exegesis.rb', line 25

def model_classes
  @model_classes ||= {}
end