Module: Morpheus::UrlBuilder

Extended by:
UrlBuilder
Included in:
UrlBuilder
Defined in:
lib/morpheus/url_builder.rb

Instance Method Summary collapse

Instance Method Details

#belongs_to(klass, id) ⇒ Object



23
24
25
# File 'lib/morpheus/url_builder.rb', line 23

def belongs_to(klass, id)
  "/#{klass.plural_url_name}/#{id}"
end

#destroy(klass, id) ⇒ Object



44
45
46
# File 'lib/morpheus/url_builder.rb', line 44

def destroy(klass, id)
  "/#{klass.plural_url_name}/#{id}"
end

#find_all(klass) ⇒ Object



13
14
15
# File 'lib/morpheus/url_builder.rb', line 13

def find_all(klass)
  "/#{klass.plural_url_name}"
end

#find_one(klass, id) ⇒ Object



5
6
7
# File 'lib/morpheus/url_builder.rb', line 5

def find_one(klass, id)
  "/#{klass.plural_url_name}/#{id}"
end

#find_some(klass, ids) ⇒ Object



9
10
11
# File 'lib/morpheus/url_builder.rb', line 9

def find_some(klass, ids)
  ["/#{klass.plural_url_name}", { :ids => ids }]
end

#has_many(primary_class, primary_key, foreign_class) ⇒ Object



31
32
33
# File 'lib/morpheus/url_builder.rb', line 31

def has_many(primary_class, primary_key, foreign_class)
  "/#{primary_class.plural_url_name}/#{primary_key}/#{foreign_class.plural_url_name}"
end

#has_one(primary_class, primary_key, foreign_class) ⇒ Object



27
28
29
# File 'lib/morpheus/url_builder.rb', line 27

def has_one(primary_class, primary_key, foreign_class)
  "/#{primary_class.plural_url_name}/#{primary_key}/#{foreign_class.singular_url_name}"
end

#relation(klass, parameters = {}) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/morpheus/url_builder.rb', line 35

def relation(klass, parameters = {})
  url_base = "/#{klass.plural_url_name}"
  if parameters.empty?
    url_base
  else
    [url_base, parameters]
  end
end

#save(klass, id, parameters) ⇒ Object



17
18
19
20
21
# File 'lib/morpheus/url_builder.rb', line 17

def save(klass, id, parameters)
  url_base = "/#{klass.plural_url_name}"
  url_base << "/#{id}" if id
  [url_base, parameters]
end