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
21
22
# File 'lib/sinatras-hat/resource.rb', line 10

def path(suffix, record=nil)
  suffix = suffix.dup
  
  parents = path_records_for(record) if record
  
  path = resources.inject("") do |memo, maker|
    memo += fragment(maker, record)
  end
  
  path = clean(path + suffix)
  path.gsub!(/:(\w+)/) { parents.pop.send(@maker.to_param) } if record
  path
end