Class: Sinatra::Hat::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatras-hat/resource.rb

Overview

Handles the logic of generating a path for a given resource, taking any and all parents into consideration.

Instance Method Summary collapse

Constructor Details

#initialize(maker) ⇒ Resource

Returns a new instance of Resource.



6
7
8
# File 'lib/sinatras-hat/resource.rb', line 6

def initialize(maker)
  @maker = maker
end

Instance Method Details

#path(suffix, record = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/sinatras-hat/resource.rb', line 10

def path(suffix, record=nil)
  suffix = suffix.dup
  
  path = resources.inject("") do |memo, maker|
    memo += fragment(record, maker)
  end
  
  suffix.gsub!('/:id', "/#{record.id}") if record
  
  clean(path + suffix)
end