Sha256: 3a553ce44b0a46bfd7870b96a3cc2946807bcc77a2314857bd9f9353c11a6b1a

Contents?: true

Size: 1.18 KB

Versions: 5

Compression:

Stored size: 1.18 KB

Contents

module N4j::Entity::Representation
  extend ActiveSupport::Concern
  included do
    include Comparable
  end
  module ClassMethods
  end

  def <=>(another_object)
    if self.class.ancestors.include?(N4j::Entity)
      url <=> another_object.url
    else
      super(another_object)
    end
  end

  def to_key
    persisted? ? [path[/\d+\Z/]] : nil
  end

  def url
    from_neo4j['self']
  end

  def path
    from_neo4j_relative['self'] ||
    (place_in_batch ? "{#{place_in_batch}}" : nil)
  end

  def create_path
    raise 'Override in Node/Relationship'
  end

  def update_path
    from_neo4j_relative['properties']
  end

  def body_hash
    raise 'Override in Node/Relationship'
  end

  def persist_hash(opts = {})
    if needs_persist?
      persisted? ? update_hash(opts) : create_hash(opts)
    end
  end

  def create_hash(opts={})
    { :to => create_path, :method => 'POST', :body => body_hash }.merge(opts)
  end

  def update_hash(opts={})
    {:to => update_path, :method => 'PUT', :body => body_hash}.merge(opts)
  end

  def destroy_hash(opts={})
    {:to => path, :method => 'DELETE'}.merge(opts)
  end

  def show_hash(opts={})
    {:to => path, :method => 'GET'}.merge(opts)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
n4j-0.0.1.4 lib/n4j/representation.rb
n4j-0.0.1.3 lib/n4j/representation.rb
n4j-0.0.1.2 lib/n4j/representation.rb
n4j-0.0.1.1 lib/n4j/representation.rb
n4j-0.0.1 lib/n4j/representation.rb