Class: FitApi::Router::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/fit_api/router/mapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMapper

Returns a new instance of Mapper.



8
9
10
11
# File 'lib/fit_api/router/mapper.rb', line 8

def initialize
  @routes = Hash.new { |h,k| h[k] = [] }
  @namespaces = []
end

Instance Attribute Details

#routesObject (readonly)

Returns the value of attribute routes.



6
7
8
# File 'lib/fit_api/router/mapper.rb', line 6

def routes
  @routes
end

Instance Method Details

#collection(&block) ⇒ Object



39
40
41
# File 'lib/fit_api/router/mapper.rb', line 39

def collection(&block)
  instance_eval &block
end

#controller(controller, &block) ⇒ Object



53
54
55
56
57
# File 'lib/fit_api/router/mapper.rb', line 53

def controller(controller, &block)
  @controller = controller
  instance_eval &block
  @controller = nil
end

#member(&block) ⇒ Object



35
36
37
# File 'lib/fit_api/router/mapper.rb', line 35

def member(&block)
  namespace '/:id', &block
end

#namespace(path, options = {}, &block) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/fit_api/router/mapper.rb', line 43

def namespace(path, options = {}, &block)
  @namespaces << fix_path(path)
  if controller = options[:controller] || path
    previous, @controller = @controller, controller
  end
  instance_eval &block
  @controller = previous if controller
  @namespaces.pop
end

#not_found(to:) ⇒ Object



31
32
33
# File 'lib/fit_api/router/mapper.rb', line 31

def not_found(to:)
  get '/404', to: to
end

#root(to:) ⇒ Object



27
28
29
# File 'lib/fit_api/router/mapper.rb', line 27

def root(to:)
  get '', to: to
end