Class: Neography::Rest::Properties

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/neography/rest/properties.rb

Direct Known Subclasses

NodeProperties, RelationshipProperties

Instance Method Summary collapse

Methods included from Helpers

#get_id, #json_content_type

Constructor Details

#initialize(connection) ⇒ Properties

Returns a new instance of Properties.



6
7
8
# File 'lib/neography/rest/properties.rb', line 6

def initialize(connection)
  @connection = connection
end

Instance Method Details

#get(id, *properties) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/neography/rest/properties.rb', line 22

def get(id, *properties)
  if properties.none?
    @connection.get(all_path(:id => get_id(id)))
  else
    get_each(id, *properties)
  end
end

#get_each(id, *properties) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/neography/rest/properties.rb', line 30

def get_each(id, *properties)
  retrieved_properties = properties.flatten.inject({}) do |memo, property|
    value = @connection.get(single_path(:id => get_id(id), :property => property))
    memo[property] = value unless value.nil?
    memo
  end
  return nil if retrieved_properties.empty?
  retrieved_properties
end

#remove(id, *properties) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/neography/rest/properties.rb', line 40

def remove(id, *properties)
  if properties.none?
    @connection.delete(all_path(:id => get_id(id)))
  else
    remove_each(id, *properties)
  end
end

#remove_each(id, *properties) ⇒ Object



48
49
50
51
52
# File 'lib/neography/rest/properties.rb', line 48

def remove_each(id, *properties)
  properties.flatten.each do |property|
    @connection.delete(single_path(:id => get_id(id), :property => property))
  end
end

#reset(id, properties) ⇒ Object



17
18
19
20
# File 'lib/neography/rest/properties.rb', line 17

def reset(id, properties)
  options = { :body => properties.to_json, :headers => json_content_type }
  @connection.put(all_path(:id => get_id(id)), options)
end

#set(id, properties) ⇒ Object



10
11
12
13
14
15
# File 'lib/neography/rest/properties.rb', line 10

def set(id, properties)
  properties.each do |property, value|
    options = { :body => value.to_json, :headers => json_content_type }
    @connection.put(single_path(:id => get_id(id), :property => property), options)
  end
end