lib/dato/api_client.rb in dato-0.6.3.beta vs lib/dato/api_client.rb in dato-0.6.3

- old
+ new

@@ -35,18 +35,15 @@ schema = JsonSchema.parse!(JSON.parse(response.body)) schema.expand_references! schema.definitions.each do |type, schema| is_collection = schema.links.select{|x| x.rel === "instances"}.any? + namespace = is_collection ? type.pluralize : type - if is_collection - type = type.pluralize - end - - define_method(type) do + define_method(namespace) do instance_variable_set( - "@#{type}", - instance_variable_get("@#{type}") || + "@#{namespace}", + instance_variable_get("@#{namespace}") || Dato::Repo.new(self, type, schema) ) end end end