Module: Exegesis
- Extended by:
- Exegesis
- Included in:
- Exegesis
- Defined in:
- lib/exegesis/database/designs.rb,
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/database/rest.rb,
lib/exegesis/database/documents.rb,
lib/exegesis/database/singleton.rb,
lib/exegesis/document/attachment.rb,
lib/exegesis/document/collection.rb,
lib/exegesis/document/attachments.rb,
lib/exegesis/document/generic_document.rb
Overview
tests for this module are in test/design_test.rb
Defined Under Namespace
Modules: Database, Document, Http, Model Classes: Design, DocumentCollection, GenericDocument, Server
Instance Method Summary collapse
-
#constantize(camel_cased_word) ⇒ Object
extracted from Extlib.
- #instantiate(doc, database) ⇒ Object
-
#nameify(name) ⇒ Object
turns class/module names into valid database names.
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
34 35 36 37 38 39 40 41 |
# File 'lib/exegesis.rb', line 34 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
48 49 50 51 52 |
# File 'lib/exegesis.rb', line 48 def instantiate(doc, database) doc = constantize(doc['class']).new(doc) doc.database = database if doc.respond_to?(:database=) doc end |
#nameify(name) ⇒ Object
turns class/module names into valid database names
44 45 46 |
# File 'lib/exegesis.rb', line 44 def nameify(name) name.gsub(/([a-z])([A-Z])/) { "#{$1}_#{$2.downcase}"}.gsub(/[A-Z]/) {|m| m.downcase }.gsub(/::/,'/') end |