Class: Shackleton::Builder
- Inherits:
-
Object
- Object
- Shackleton::Builder
show all
- Extended by:
- Forwardable
- Defined in:
- lib/shackleton/builder.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kwargs, &block) ⇒ Object
24
25
26
27
|
# File 'lib/shackleton/builder.rb', line 24
def method_missing(method, *args, **kwargs, &block)
return self.add_route(stack.last[method.to_sym], kwargs) if stack.last[method.to_sym]
super
end
|
Instance Method Details
#add_route(route, kwargs) ⇒ Object
15
16
17
18
|
# File 'lib/shackleton/builder.rb', line 15
def add_route(route, kwargs)
stack << Shackleton::Fragment.new(route, kwargs)
self
end
|
#build ⇒ Object
11
12
13
|
# File 'lib/shackleton/builder.rb', line 11
def build
[stack.map(&:call).compact.join('/').gsub(%r{/+}, '/'), query_params].reject(&:empty?).join("?")
end
|
#query_params ⇒ Object
20
21
22
|
# File 'lib/shackleton/builder.rb', line 20
def query_params
URI.encode_www_form(Hash[*stack.map {|x| x.query_params.to_a}.flatten])
end
|
#stack ⇒ Object
7
8
9
|
# File 'lib/shackleton/builder.rb', line 7
def stack
@stack ||= []
end
|