From 4963f16f3eb0a3f3a6dd7fbdc3b7f3aeab8d57cc Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Tue, 13 May 2014 01:27:26 +0500 Subject: [PATCH] add special method that lists available actions for client --- lib/gitlab.rb | 8 ++++++++ spec/gitlab_spec.rb | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/gitlab.rb b/lib/gitlab.rb index e3862e609..95c382678 100644 --- a/lib/gitlab.rb +++ b/lib/gitlab.rb @@ -26,4 +26,12 @@ def self.method_missing(method, *args, &block) def self.respond_to?(method) return client.respond_to?(method) || super end + + # Returns an unsorted array of available client methods. + # + # @return [Array] + def self.actions + hidden = /endpoint|private_token|user_agent|sudo|get|post|put|\Adelete\z|validate|set_request_defaults/ + (Gitlab::Client.instance_methods - Object.methods).reject {|e| e[hidden]} + end end diff --git a/spec/gitlab_spec.rb b/spec/gitlab_spec.rb index 7ea769371..f037e70aa 100644 --- a/spec/gitlab_spec.rb +++ b/spec/gitlab_spec.rb @@ -9,6 +9,15 @@ end end + describe ".actions" do + it "should return an array of client methods" do + actions = Gitlab.actions + expect(actions).to be_an Array + expect(actions.first).to be_a Symbol + expect(actions.sort.first).to match(/add_/) + end + end + describe ".endpoint=" do it "should set endpoint" do Gitlab.endpoint = 'https://api.example.com'