lib/exegesis.rb in mattly-exegesis-0.0.10 vs lib/exegesis.rb in mattly-exegesis-0.2.0
- old
+ new
@@ -1,43 +1,36 @@
require 'time'
require 'pathname'
+require 'restclient'
+require 'json'
-require 'couchrest'
-
$:.unshift File.dirname(__FILE__) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
+require 'monkeypatches/time'
+
module Exegesis
- autoload :Document, 'exegesis/document'
- autoload :Design, 'exegesis/design'
+ autoload :Http, 'exegesis/utils/http'
+
+ autoload :Server, 'exegesis/server'
+ autoload :Database, 'exegesis/database'
+
+ autoload :Model, 'exegesis/model'
+ autoload :Document, 'exegesis/document'
+ autoload :Designs, 'exegesis/designs'
+ autoload :Design, 'exegesis/design'
+
extend self
- def designs_directory= dir
- @designs_directory = Pathname.new(dir)
+ def model_classes
+ @model_classes ||= {}
end
- def designs_directory
- @designs_directory ||= Pathname.new(ENV["PWD"])
- @designs_directory
- end
-
- def design_file name
- File.read(designs_directory + name)
- end
-
- def database_template= template
- @db_template = template
- end
-
- def database_template
- @db_template ||= "http://localhost:5984/%s"
- end
-
- def database_for name
- database_template % name
- end
-
- def document_classes
- @document_classes ||= Hash.new(Exegesis::Document)
+ def instantiate hash, database=nil
+ return nil if hash.nil?
+ klass = model_classes[hash['class']]
+ obj = klass.nil? ? hash : klass.new(hash)
+ obj.database = database if obj.respond_to?(:database=)
+ obj
end
end
\ No newline at end of file