lib/persevere_adapter.rb in dm-persevere-adapter-0.15 vs lib/persevere_adapter.rb in dm-persevere-adapter-0.16.0
- old
+ new
@@ -5,11 +5,10 @@
require 'persevere'
module DataMapper
module Adapters
class PersevereAdapter < AbstractAdapter
- VERSION='0.15'
##
# Used by DataMapper to put records into a data-store: "INSERT"
# in SQL-speak. It takes an array of the resources (model
# instances) to be saved. Resources each have a key that can be
# used to quickly look them up later without searching, if the
@@ -152,11 +151,11 @@
connect if @persevere.nil?
resources = Array.new
json_query = make_json_query(query)
- tblname = Extlib::Inflection.classify(query.model).pluralize
+ tblname = Extlib::Inflection.classify(query.model)
path = "/#{tblname}/#{json_query}"
response = @persevere.retrieve(path)
if response.code == "200"
@@ -170,12 +169,10 @@
end
end
end
resources = query.model.load(results, query)
- else
- return false
end
query.filter_records(resources)
end
@@ -213,10 +210,36 @@
end
end
return deleted
end
+ ##
+ #
+ # Other methods for the Yogo Data Management Toolkit
+ #
+ ##
+ def get_schema(name = nil, project = nil)
+ path = nil
+ if name.nil? & project.nil?
+ path = "/Class/"
+ elsif project.nil?
+ path = "/Class/#{name}"
+ elsif name.nil?
+ path = "/Class/#{project}/"
+ else
+ path = "/Class/#{project}/#{name}"
+ end
+
+ response = @persevere.retrieve(path)
+
+ if response.code == "200"
+ return JSON.parse(response.body)
+ else
+ return nil
+ end
+ end
+
private
##
# Make a new instance of the adapter. The @model_records ivar is
# the 'data-store' for this adapter. It is not shared amongst
@@ -252,15 +275,19 @@
@resource_naming_convention = NamingConventions::Resource::Underscored
@identity_maps = {}
@classes = []
@persevere = nil
@prepped = false
+
+ connect
end
def connect
- uri = URI::HTTP.build(@options).to_s
- @persevere = Persevere.new(uri)
- prep_persvr unless @prepped
+ if ! @prepped
+ uri = URI::HTTP.build(@options).to_s
+ @persevere = Persevere.new(uri)
+ prep_persvr unless @prepped
+ end
end
def prep_persvr
# Because this is an AbstractAdapter and not a
# DataObjectAdapter, we can't assume there are any schemas