Module: Neography::Rest::Paths

Instance Method Summary collapse

Instance Method Details

#add_path(key, path) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/neography/rest/paths.rb', line 5

def add_path(key, path)
  method_name = :"#{key}_path"

  metaclass = (class << self; self; end)
  metaclass.instance_eval do
    define_method method_name do |*attributes|
      if attributes.any?
        build_path(path, *attributes)
      else
        path
      end
    end
  end

  define_method method_name do |*attributes|
    self.class.send(method_name, *attributes)
  end
end

#build_path(path, attributes) ⇒ Object



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

def build_path(path, attributes)
  path.gsub(/:([\w_]*)/) do
    encode(attributes[$1.to_sym].to_s)
  end
end

#encode(value) ⇒ Object



30
31
32
# File 'lib/neography/rest/paths.rb', line 30

def encode(value)
  URI.encode(value).gsub("/","%2F")
end