lib/github_api/api/actions.rb in github_api-0.12.0 vs lib/github_api/api/actions.rb in github_api-0.12.1

- old
+ new

@@ -1,48 +1,58 @@ # encoding: utf-8 module Github - # Core class responsible for api interface operations + # Responsible for providing inspection of api methods class API # Returns all API public methods for a given class. + # + # @return [nil] + # + # @api public def self.extend_with_actions(child_class) child_class.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 def self.actions - self.new.api_methods_in(#{child_class}) + self.new.api_methods_in(#{child_class}) + + self.new.module_methods_in(#{child_class}) end + def actions - api_methods_in(#{child_class}) + api_methods_in(#{child_class}) + module_methods_in(#{child_class}) end RUBY_EVAL end + # Finds api methods in a class + # + # @param [Class] klass + # The klass to inspect for methods. + # + # @api private def api_methods_in(klass) - puts "---" - (klass.send(:instance_methods, false) - ['actions']).sort.each do |method| - puts "|--> #{method}" + methods = klass.send(:instance_methods, false) - [:actions] + methods.sort.each_with_object([]) do |method_name, accumulator| + unless method_name.to_s.include?('with') || + method_name.to_s.include?('without') + accumulator << method_name + end + accumulator end - klass.included_modules.each do |mod| + end + + # Finds methods included through class modules + # + # @param [Class] klass + # The klass to inspect for methods. + # + # @api private + def module_methods_in(klass) + klass.included_modules.each_with_object([]) do |mod, accumulator| if mod.to_s =~ /#{klass}/ - puts "| \\ #{mod.to_s}" - mod.instance_methods(false).each do |met| - puts "| |--> #{met}" + mod.instance_methods(false).each do |method| + accumulator << method end - puts "| /" end + accumulator end - puts "---" - nil - end - - def append_arguments(method) - _method = self.method(method) - if _method.arity == 0 - args = "()" - elsif _method.arity > 0 - args = "(few)" - else - args = "(else)" - end - args end end # API end # Github