module Gump

Constants

VERSION

Public Class Methods

scan() click to toggle source
# File lib/gump.rb, line 4
def self.scan
        apis = {}
        dirs = [Dir.pwd]
        dirs.each do |dir|
                Dir[dir + '/*'].each do |f|
                        if File.ftype(f) == 'file'
                                tmps = scan_file(f) #if f.end_with?(".rb") || f.end_with?(".ru")
                                if tmps && tmps.size > 0
                                        apis[f.split(".").first.split('/').last] = tmps
                                end
                        elsif File.ftype(f) == 'directory'
                                dirs << f
                        end
                end
        end

        path =  File.dirname(__FILE__)+"/../server"
        File.open("#{path}/apis.yml", "wb") do |f|
                YAML.dump(apis, f)
        end
end
scan_file(filename) click to toggle source
# File lib/gump.rb, line 26
def self.scan_file(filename)
        apis,api = [],nil
        File.open(filename, "r") do |file|
                while line=file.gets
                        re=/\A#[\s]+(API|DESC|PARAMS|RETURN|GET|POST|DELETE|PUT)/i
                        result = re.match(line.strip!)
                        if result
                                key = result[1]
                                api = {} and next if "API" == key
                                if ["GET","POST","DELETE","PUT"].include?(key)
                                        api["method"] = key.downcase
                                        api["url"] = result.post_match.strip.to_s
                                else
                                        api[key.downcase] = result.post_match.strip.to_s
                                end
                        else
                                api.to_h.any? and apis << api
                                api = nil
                        end
                end
        end
 apis
end