Class: ForestAdminAgent::Routes::AbstractRoute

Inherits:
Object
  • Object
show all
Defined in:
lib/forest_admin_agent/routes/abstract_route.rb

Instance Method Summary collapse

Constructor Details

#initializeAbstractRoute

Returns a new instance of AbstractRoute.



4
5
6
7
# File 'lib/forest_admin_agent/routes/abstract_route.rb', line 4

def initialize
  @routes = {}
  setup_routes
end

Instance Method Details

#add_route(name, method, uri, closure, format = 'json') ⇒ Object



30
31
32
# File 'lib/forest_admin_agent/routes/abstract_route.rb', line 30

def add_route(name, method, uri, closure, format = 'json')
  @routes[name] = { method: method, uri: uri, closure: closure, format: format }
end

#build(args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/forest_admin_agent/routes/abstract_route.rb', line 9

def build(args)
  context = RequestContext.new
  context.datasource = ForestAdminAgent::Facades::Container.datasource

  if args[:params]['collection_name']
    begin
      context.collection = context.datasource.get_collection(args[:params]['collection_name'])
    rescue ForestAdminDatasourceToolkit::Exceptions::ForestException => e
      raise Http::Exceptions::NotFoundError, e.message if e.message.include?('not found')

      raise
    end
  end

  context
end

#routesObject



26
27
28
# File 'lib/forest_admin_agent/routes/abstract_route.rb', line 26

def routes
  @routes ||= {}
end

#setup_routesObject

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/forest_admin_agent/routes/abstract_route.rb', line 34

def setup_routes
  raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'"
end