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
20
21
22
23
24
25
26
# File 'lib/praxis/skeletor/restful_routing_config.rb', line 7

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

  @version_prefix = ""
  if resource_definition.version_options
    version_using = Array(resource_definition.version_options[:using])
    if version_using.include?(:path)  
      @version_prefix = "#{Praxis::Request::path_version_prefix}#{resource_definition.version}"
    end
  end
  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



46
47
48
49
50
# File 'lib/praxis/skeletor/restful_routing_config.rb', line 46

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

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

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



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

def any(path, opts={})     add_route 'ANY',       path, opts end

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



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

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

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



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

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

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



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

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

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



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

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

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



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

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

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



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

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

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



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

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

#prefix(prefix = nil) ⇒ Object



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

def prefix(prefix=nil)
  @path_prefix = prefix if prefix
  @version_prefix + @path_prefix 
end

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



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

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

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



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

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