Module: Neography::Property

Included in:
Node, Relationship
Defined in:
lib/neography/property.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.method_missing(method_sym, *arguments, &block) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/neography/property.rb', line 44

def self.method_missing(method_sym, *arguments, &block)
  if (method_sym.to_s =~ /$=/) != nil
    new_ostruct_member(method_sym.to_s.chomp("="))
  else
    super
  end
end

Instance Method Details

#[](key) ⇒ Object



5
6
7
8
# File 'lib/neography/property.rb', line 5

def [](key)
  return unless respond_to?(key)
  @table[key]
end

#[]=(key, value) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/neography/property.rb', line 10

def []=(key, value)
  k = key.to_s
  if value.nil?
    if self.is_a? Neography::Node
      neo_server.remove_node_properties(self.neo_id, [key])
    else
      neo_server.remove_relationship_properties(self.neo_id, [key])
    end
  else
    if self.is_a? Neography::Node
      neo_server.set_node_properties(self.neo_id, {k => value})
    else
      neo_server.set_relationship_properties(self.neo_id, {k => value})
    end
    new_ostruct_member(k) unless self.respond_to?(key)
  end
  @table[key] = value
end

#new_ostruct_member(name) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/neography/property.rb', line 30

def new_ostruct_member(name)
  name = name.to_sym
  unless self.respond_to?(name)
    meta = class << self; self; end
    meta.send(:define_method, name) { @table[name] }
    meta.send(:define_method, "#{name}=") do |x| 
      @table[name] = x 
      self[name.to_sym] = x        
    end
  end
 name
end