Module: N4j::Entity::Representation

Extended by:
ActiveSupport::Concern
Defined in:
lib/n4j/representation.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#<=>(another_object) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/n4j/representation.rb', line 9

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

#body_hashObject



41
42
43
# File 'lib/n4j/representation.rb', line 41

def body_hash
  raise 'Override in Node/Relationship'
end

#create_hash(opts = {}) ⇒ Object



51
52
53
# File 'lib/n4j/representation.rb', line 51

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

#create_pathObject



33
34
35
# File 'lib/n4j/representation.rb', line 33

def create_path
  raise 'Override in Node/Relationship'
end

#destroy_hash(opts = {}) ⇒ Object



59
60
61
# File 'lib/n4j/representation.rb', line 59

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

#pathObject



25
26
27
# File 'lib/n4j/representation.rb', line 25

def path
  from_neo4j_relative['self'] || place_in_batch_path
end

#persist_hash(opts = {}) ⇒ Object



45
46
47
48
49
# File 'lib/n4j/representation.rb', line 45

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

#place_in_batch_pathObject



29
30
31
# File 'lib/n4j/representation.rb', line 29

def place_in_batch_path
  (place_in_batch ? "{#{place_in_batch}}" : nil)
end

#show_hash(opts = {}) ⇒ Object



63
64
65
# File 'lib/n4j/representation.rb', line 63

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

#to_keyObject



17
18
19
# File 'lib/n4j/representation.rb', line 17

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

#update_hash(opts = {}) ⇒ Object



55
56
57
# File 'lib/n4j/representation.rb', line 55

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

#update_pathObject



37
38
39
# File 'lib/n4j/representation.rb', line 37

def update_path
  from_neo4j_relative['properties']
end

#urlObject



21
22
23
# File 'lib/n4j/representation.rb', line 21

def url
  from_neo4j['self'] || place_in_batch_path
end