Class: Praxis::Skeletor::RestfulRoutingConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/praxis/skeletor/restful_routing_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, resource_definition, &block) ⇒ RestfulRoutingConfig

Returns a new instance of RestfulRoutingConfig.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/praxis/skeletor/restful_routing_config.rb', line 7

def initialize(name, resource_definition, &block)
  @name = name
  @resource_definition = resource_definition
  @routes = []

  @prefix = "/" + resource_definition.name.split("::").last.underscore

  if resource_definition.routing_config
    instance_eval(&resource_definition.routing_config)
  end

  instance_eval(&block)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/praxis/skeletor/restful_routing_config.rb', line 5

def name
  @name
end

#resource_definitionObject (readonly)

Returns the value of attribute resource_definition.



5
6
7
# File 'lib/praxis/skeletor/restful_routing_config.rb', line 5

def resource_definition
  @resource_definition
end

#routesObject (readonly)

Returns the value of attribute routes.



5
6
7
# File 'lib/praxis/skeletor/restful_routing_config.rb', line 5

def routes
  @routes
end

Instance Method Details

#add_route(verb, path, options = {}) ⇒ Object



36
37
38
39
40
# File 'lib/praxis/skeletor/restful_routing_config.rb', line 36

def add_route(verb, path, options={})
  path = Mustermann.new(@prefix + path)

  @routes << Route.new(verb, path, resource_definition.version, **options)
end

#connect(path, opts = {}) ⇒ Object



33
# File 'lib/praxis/skeletor/restful_routing_config.rb', line 33

def connect(path, opts={}) add_route 'CONNECT', path, opts end

#delete(path, opts = {}) ⇒ Object



31
# File 'lib/praxis/skeletor/restful_routing_config.rb', line 31

def delete(path, opts={})  add_route 'DELETE',  path, opts end

#get(path, opts = {}) ⇒ Object



27
# File 'lib/praxis/skeletor/restful_routing_config.rb', line 27

def get(path, opts={})     add_route 'GET',     path, opts end

#head(path, opts = {}) ⇒ Object



28
# File 'lib/praxis/skeletor/restful_routing_config.rb', line 28

def head(path, opts={})    add_route 'HEAD',    path, opts end

#options(path, opts = {}) ⇒ Object



26
# File 'lib/praxis/skeletor/restful_routing_config.rb', line 26

def options(path, opts={}) add_route 'OPTIONS', path, opts end

#patch(path, opts = {}) ⇒ Object



34
# File 'lib/praxis/skeletor/restful_routing_config.rb', line 34

def patch(path, opts={})   add_route 'PATCH',   path, opts end

#post(path, opts = {}) ⇒ Object



29
# File 'lib/praxis/skeletor/restful_routing_config.rb', line 29

def post(path, opts={})    add_route 'POST',    path, opts end

#prefix(prefix = nil) ⇒ Object



21
22
23
24
# File 'lib/praxis/skeletor/restful_routing_config.rb', line 21

def prefix(prefix=nil)
  return @prefix unless prefix
  @prefix = prefix
end

#put(path, opts = {}) ⇒ Object



30
# File 'lib/praxis/skeletor/restful_routing_config.rb', line 30

def put(path, opts={})     add_route 'PUT',     path, opts end

#trace(path, opts = {}) ⇒ Object



32
# File 'lib/praxis/skeletor/restful_routing_config.rb', line 32

def trace(path, opts={})   add_route 'TRACE',   path, opts end