Class: Herbert::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/herbert/Resource.rb

Overview

When extended, it virtually “merges” the overriding class into the app.

class Messages
 get '/'
 end
end

will enable your app to respond to

GET /messages/

Class Method Summary collapse

Class Method Details

.inherited(subclass) ⇒ Object

Translates Sinatra DSL calls



18
19
20
21
22
23
24
# File 'lib/herbert/Resource.rb', line 18

def self.inherited(subclass)
  %w{get post put delete}.each do |verb|
    subclass.define_singleton_method verb.to_sym  do |route, &block|
      app.send verb.to_sym, "/#{subclass.to_s.downcase}#{route}", &block
    end
  end
end

.newObject

Instantizing this class is forbidden

Raises:

  • (StandardError)


13
14
15
# File 'lib/herbert/Resource.rb', line 13

def self.new
  raise StandardError.new('You are not allowed to instantize this class directly')
end