您好我正在使用intridea的葡萄开发一个简单的红宝石api。假设我们有这个:
class API_v1 < Grape::API
resource :foo do
end
resource :bar do
end
end
我怎样才能使:foo
和:bar
的声明位于不同的文件中?基本上,我想知道是否有可能有类似于rails控制器的东西,其中有多个文件来组织代码。
我希望有人可以告诉我如何实现这一目标。
答案 0 :(得分:8)
Ruby有open classes,因此您应该只需将它们移动到单独的文件中。
# foo.rb
class API_v1 < Grape::API
resource :foo do
end
end
# bar.rb
class API_v1 < Grape::API
resource :bar do
end
end
答案 1 :(得分:8)
README建议您使用mount
:
class Foo < Grape::API
resource :foo ...
end
class Bar < Grape::API
resource :bar ...
end
class API < Grape::API
mount Foo
mount Bar
end