-
Install api-interface gem
-
Create a module for your api and extend ApiInterface
-
You can start registering methods, modules and classes to your Api.
Note: Methods, Modules and Classes are only added if they do not exist in the Api already. (not overwritten)
module MyApi extend ApiInterface register :method, Path::To::Method::Container, :method_name end
Now you can call MyApi::method_name and Path::To::Method::Container::method_name will be called in the background.
module MyApi extend ApiInterface register :module, Path::To::MyModule, :ModuleNameInAPI end
Now you can use MyApi::ModuleNameInAPI to access all public/protected methods of Path::To::MyModule.
module MyApi extend ApiInterface register :class, Path::To::Klass, :Class4Api end
Now you can use MyApi::Class4Api to access all public/protected methods ofPath::To::Klass.
Your code base:
module Hello module World class Klass def foo puts "Hello Klass#foo" end end module B def self.bar puts "Hello self.bar" end end module C def foo puts "Hello foo" end def bar puts "Hello bar" end end end end
Your API:
module Hello module World module Api extend ApiInterface register :method, Hello::World::B, :bar register :module, Hello::World::C, :Module4Api register :class, Hello::World::Klass, :Class4Api end end end
Testing it words:
puts "---- testing register :method ----" Hello::World::Api::bar puts "---- testing register :module ----" Hello::World::Api::Module4Api.foo puts "---- testing register :class ----" Hello::World::Api::Class4Api.new.foo
Result:
---- testing register :method ---- Hello self.bar ---- testing register :module ---- Hello foo ---- testing register :class ---- Hello Klass#foo
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Copyright © 2010 Adrien (adrien[at]gn2fr) . See LICENSE for details.