Sha256: 39291c1e7914fd17634b1ac50264f4041b7b8ea39cc018428179715cc1932064

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 KB

Contents

require 'time'
require 'pathname'
require 'restclient'
require 'json'

$:.unshift File.dirname(__FILE__) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))

require 'monkeypatches/time'

module Exegesis
  autoload :Http,               'exegesis/utils/http'
                                
  autoload :Server,             'exegesis/server'
  autoload :Database,           'exegesis/database'
                                
  autoload :Model,              'exegesis/model'
  autoload :Document,           'exegesis/document'
  autoload :GenericDocument,    'exegesis/document/generic_document'
  
  autoload :Design,             'exegesis/design'
  autoload :DocumentCollection, 'exegesis/document/collection'
    
  extend self
  
  # 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.
  #
  # @example
  # "Module".constantize #=> Module
  # "Class".constantize #=> Class
  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
  
  # turns class/module names into valid database names
  def nameify(name)
    name.gsub(/([a-z])([A-Z])/) { "#{$1}_#{$2.downcase}"}.gsub(/[A-Z]/) {|m| m.downcase }.gsub(/::/,'/')
  end
  
  def instantiate(doc, database)
    doc = constantize(doc['class']).new(doc)
    doc.database = database if doc.respond_to?(:database=)
    doc
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mattly-exegesis-0.2.8 lib/exegesis.rb