maxdemarzi/neography — pull request #58 by rdvdijk (2012-09-08 21:09:35+00:00)
Title: Major refactor of Rest class

This is a major refactoring of the Rest class, which is currently [too big and complex](https://codeclimate.com/github/maxdemarzi/neography/Neography::Rest).

I've split up the Rest class into multiple classes and modules:

```sh
lib/neography/connection.rb
lib/neography/rest/batch.rb
lib/neography/rest/clean.rb
lib/neography/rest/cypher.rb
lib/neography/rest/gremlin.rb
lib/neography/rest/helpers.rb
lib/neography/rest/node_auto_indexes.rb
lib/neography/rest/node_indexes.rb
lib/neography/rest/node_paths.rb
lib/neography/rest/node_properties.rb
lib/neography/rest/node_relationships.rb
lib/neography/rest/node_traversal.rb
lib/neography/rest/nodes.rb
lib/neography/rest/paths.rb
lib/neography/rest/relationship_auto_indexes.rb
lib/neography/rest/relationship_indexes.rb
lib/neography/rest/relationship_properties.rb
lib/neography/rest/relationships.rb
```

The Rest class now does calls to all of these smaller classes. The smaller classes clearly define the REST urls and can be called using helper methods. Here is an example of the Relationships class. It defines one path `base` with value `/relationship/:id`, which is expanded with `base_path(:id => "42")` to the path `/relationship/42`:

```ruby
module Neography
class Rest
class Relationships
include Neography::Rest::Paths
include Neography::Rest::Helpers

add_path :base, "/relationship/:id"

def initialize(connection)
@connection = connection
end

def get(id)
@connection.get(base_path(:id => get_id(id)))
end

def delete(id)
@connection.delete(base_path(:id => get_id(id)))
end

end
end
end
```

I've also added unit tests to all of these classes and modules. The only class that now needs unit tests is the (still complex) Batch class.

All existing integration tests pass.