Class: NeoRest::Relationship

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/NeoRest/relationship.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = nil) ⇒ Relationship

Returns a new instance of Relationship.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/NeoRest/relationship.rb', line 11

def initialize( hash = nil )
  @table = {}
  if hash
    @neo_id = hash["self"].split('/').last
    @neo_url = hash["self"]
    @start_id = hash["start"].split('/').last
    @end_id = hash["end"].split('/').last
    @type = hash["type"]

    for key, value in hash["data"]
      @table[key.to_sym] = value
      new_ostruct_member(key)
    end
  end
end

Instance Attribute Details

#end_idObject (readonly)

Returns the value of attribute end_id.



9
10
11
# File 'lib/NeoRest/relationship.rb', line 9

def end_id
  @end_id
end

#neo_idObject (readonly)

Returns the value of attribute neo_id.



9
10
11
# File 'lib/NeoRest/relationship.rb', line 9

def neo_id
  @neo_id
end

#neo_urlObject (readonly)

Returns the value of attribute neo_url.



9
10
11
# File 'lib/NeoRest/relationship.rb', line 9

def neo_url
  @neo_url
end

#start_idObject (readonly)

Returns the value of attribute start_id.



9
10
11
# File 'lib/NeoRest/relationship.rb', line 9

def start_id
  @start_id
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/NeoRest/relationship.rb', line 9

def type
  @type
end

Class Method Details

.delete(relationship_id) ⇒ Object



60
61
62
# File 'lib/NeoRest/relationship.rb', line 60

def delete relationship_id
  RestClient.delete( "#{$neo_base_url}/relationship/#{relationship_id}" )
end

.load(relationship_id) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/NeoRest/relationship.rb', line 47

def load relationship_id
  RestClient.get( "#{$neo_base_url}/relationship/#{relationship_id}", :accept => :json ){ |response, request, result, &block|
    case response.code
      when 200
        NeoRest::Node.new( JSON.parse( response ) )
      when 404
        return nil
      else
        response.return!(request, result, &block)
    end
  }
end

Instance Method Details

#deleteObject



41
42
43
# File 'lib/NeoRest/relationship.rb', line 41

def delete
  NeoRest::Relationship.delete neo_id
end

#update(properties = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/NeoRest/relationship.rb', line 27

def update properties = {}
  if not properties.empty?
    @table.each { | key, value | delete_field( key ) }
    @table.clear
    
    for key, value in properties
      @table[key.to_sym] = value
      new_ostruct_member(key)
    end
  end
        
  RestClient.put( "#{$neo_base_url}/relationship/#{neo_id}/properties", @table.to_json, :content_type => :json, :accept => :json )
end