Class: Eventick::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/eventick/base.rb
Class Method Summary
collapse
Class Method Details
.path(args = {}) ⇒ Object
7
8
9
10
11
12
13
14
15
|
# File 'lib/eventick/base.rb', line 7
def self.path(args={})
if @resource
path = translate(args)
"#{ path }.json"
else
warn "The #{ self.name } class has not defined any resource path."
raise
end
end
|
.resource(res) ⇒ Object
3
4
5
|
# File 'lib/eventick/base.rb', line 3
def self.resource(res)
@resource = res
end
|
.translate(args) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/eventick/base.rb', line 17
def self.translate(args)
last_resource_rexp = /\/:(.\w+)$/
resource_keys = /(?<=:)(.\w+)/
one = @resource.gsub(last_resource_rexp).count == 0
if args.empty?
matched = @resource.gsub(last_resource_rexp, "")
else
s_args = Hash[args.map{ |k, v| [k.to_s, v] }]
matched = @resource.gsub(resource_keys, s_args)
matched.gsub!(/:/ , "")
matched.gsub!(/\/$/ , "")
end
remaining = matched.gsub(resource_keys).count
if remaining != 0
warn "Missing arguments for #{ self.name } class resource path: #{ matched }."
raise
end
matched
end
|