Module: Panda::Router::ClassMethods

Included in:
Proxy
Defined in:
lib/panda/modules/router.rb

Instance Method Summary collapse

Instance Method Details

#build_hash_many_path(end_path, relation_attr) ⇒ Object



28
29
30
31
32
# File 'lib/panda/modules/router.rb', line 28

def build_hash_many_path(end_path, relation_attr)
  relation_class_name = relation_attr[0..relation_attr.rindex("_id")-1].capitalize
  prefix_path = Panda::const_get(relation_class_name).resource_path + "/:" + relation_attr
  prefix_path + end_path
end

#element_params(url, map) ⇒ Object



38
39
40
41
42
# File 'lib/panda/modules/router.rb', line 38

def element_params(url, map)
  params = map.clone
  url.clone.scan(VAR_PATTERN).map{|key| params.reject!{|k,v| k==key[1..-1] } }
  params
end

#full_object_url(url) ⇒ Object



44
45
46
# File 'lib/panda/modules/router.rb', line 44

def full_object_url(url)
  url + ".#{DEFAULT_FORMAT}"
end

#many_pathObject



20
21
22
# File 'lib/panda/modules/router.rb', line 20

def many_path
  resource_path
end

#match(url) ⇒ Object



16
17
18
# File 'lib/panda/modules/router.rb', line 16

def match(url)
  @url = url
end

#object_url(url, map) ⇒ Object



34
35
36
# File 'lib/panda/modules/router.rb', line 34

def object_url(url, map)
  full_object_url(url.clone.gsub(VAR_PATTERN){|key| map[key[1..-1].to_sym] || map[key[1..-1].to_s]})
end

#one_pathObject



24
25
26
# File 'lib/panda/modules/router.rb', line 24

def one_path
  resource_path + "/:id"
end

#resource_pathObject



12
13
14
# File 'lib/panda/modules/router.rb', line 12

def resource_path
  @url || "/#{end_class_name.downcase}s"
end