diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index e371efa..71b1655 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -1,10 +1,7 @@ require 'forwardable' require 'neography/rest/helpers' -require 'neography/rest/paths' - require 'neography/rest/schema_indexes' - require 'neography/rest/nodes' require 'neography/rest/node_properties' require 'neography/rest/node_relationships' @@ -27,9 +24,7 @@ require 'neography/rest/transactions' require 'neography/rest/spatial' require 'neography/rest/constraints' - require 'neography/errors' - require 'neography/connection' module Neography diff --git a/lib/neography/rest/paths.rb b/lib/neography/rest/paths.rb deleted file mode 100644 index db05425..0000000 --- a/lib/neography/rest/paths.rb +++ /dev/null @@ -1,46 +0,0 @@ -module Neography - class Rest - module Paths - - def add_path(key, path) - method_name = :"#{key}_path" - - metaclass = (class << self; self; end) - metaclass.instance_eval do - define_method method_name do |*attributes| - if attributes.any? - build_path(path, *attributes) - else - path - end - end - end - - define_method method_name do |*attributes| - self.class.send(method_name, *attributes) - end - end - - - def build_path(path, attributes) - p = String.new(path) - p.gsub!(/=:([\w_]*)/) do - if $1.to_sym == :value and attributes[$1.to_sym].class == String - "=%22"+encode(attributes[$1.to_sym].to_s)+"%22"; - else - "="+encode(attributes[$1.to_sym].to_s) - end - end - - p.gsub(/:([\w_]*)/) do - encode(attributes[$1.to_sym].to_s) - end - end - - def encode(value) - CGI.escape(value).gsub("+", "%20") - end - - end - end -end diff --git a/spec/unit/rest/paths_spec.rb b/spec/unit/rest/paths_spec.rb deleted file mode 100644 index a5aa79f..0000000 --- a/spec/unit/rest/paths_spec.rb +++ /dev/null @@ -1,69 +0,0 @@ -require 'spec_helper' - -module Neography - class Rest - - class Dummy - extend Paths - - add_path :one, "/node/:id" - add_path :two, "/node/:id/properties/:property" - end - - describe Dummy do - - context "instance methods" do - - it { should respond_to(:one_path) } - it { should respond_to(:two_path) } - - it "replaces a key" do - subject.one_path(:id => 42).should == "/node/42" - end - - it "replaces multiple keys" do - subject.two_path(:id => 42, :property => "foo").should == "/node/42/properties/foo" - end - - it "url encodes spaces" do - subject.one_path(:id => "with space").should == "/node/with%20space" - end - - # URI.encode does not escape slashes (and rightly so), but should escape these keys - it "url encodes slashes" do - subject.one_path(:id => "with/slash").should == "/node/with%2Fslash" - end - - end - - context "class methods" do - - subject { Dummy } - - it { should respond_to(:one_path) } - it { should respond_to(:two_path) } - - it "replaces a key" do - subject.one_path(:id => 42).should == "/node/42" - end - - it "replaces multiple keys" do - subject.two_path(:id => 42, :property => "foo").should == "/node/42/properties/foo" - end - - it "url encodes spaces" do - subject.one_path(:id => "with space").should == "/node/with%20space" - end - - # URI.encode does not escape slashes (and rightly so), but should escape these keys - it "url encodes slashes" do - subject.one_path(:id => "with/slash").should == "/node/with%2Fslash" - end - - end - - end - - end -end -