D
dblock
I am trying to extend Grape (https://github.com/intridea/grape) to
support a more modular approach.
Grape defines the following.
module Grape
class API
class << self
def get(*paths, &block) ...
end
end
end
To use this one creates a class that derives from Grape::API.
class MyAPI < Grape::API
get "path" do ...
end
What I'd like to do is inject another definition into the MyAPI class
from, say, MyAPIMethods. So the latter would be declared like this.
module MyAPIMethods
get "someotherpath" do ...
end
Then I could write, for example:
class MyAPI < Grape::API
get "path" do ...
module MyAPIMethods
end
I'd like all the declarations of MyAPIMethods to evaluate within
MyAPI, so that it sets up routes accordingly. I can define module in
Grape::API to do anything. For example
def module(module_ref)
# what do I do here?
end
How do I evaluate a module in the context of MyAPI? Or is there a
better way to my madness?
support a more modular approach.
Grape defines the following.
module Grape
class API
class << self
def get(*paths, &block) ...
end
end
end
To use this one creates a class that derives from Grape::API.
class MyAPI < Grape::API
get "path" do ...
end
What I'd like to do is inject another definition into the MyAPI class
from, say, MyAPIMethods. So the latter would be declared like this.
module MyAPIMethods
get "someotherpath" do ...
end
Then I could write, for example:
class MyAPI < Grape::API
get "path" do ...
module MyAPIMethods
end
I'd like all the declarations of MyAPIMethods to evaluate within
MyAPI, so that it sets up routes accordingly. I can define module in
Grape::API to do anything. For example
def module(module_ref)
# what do I do here?
end
How do I evaluate a module in the context of MyAPI? Or is there a
better way to my madness?