class Rancher::ApiDiscovery::Crawler
Public Class Methods
new()
click to toggle source
# File lib/rancher/api_discovery.rb, line 11 def initialize @base_url = ENV['RANCHER_URL'] @entities = {} end
Public Instance Methods
generate_code()
click to toggle source
# File lib/rancher/api_discovery.rb, line 34 def generate_code @entities.each do |key, entity| filename = "./lib/rancher/api/models/#{key.downcase}.rb" File.write(filename, entity.code) end File.open('./lib/rancher/api/models.rb', 'w') do |file| @entities.each do |key, _| require_string = "require 'rancher/api/models/#{key.downcase}'" file.puts(require_string) end end end
run()
click to toggle source
# File lib/rancher/api_discovery.rb, line 16 def run schemas = get(@base_url + '/schemas') schemas['data'].each do |entity| @entities[entity['id']] = Entity.new(entity) end @entities.each do |key, entity| puts "Discovered: #{key}" puts "helpers: #{entity.helpers}" puts "has_many: #{entity.has_many}" puts "has_one: #{entity.has_one}" puts "belongs_to: #{entity.belongs_to}" puts "attributes: #{entity.attributes}" puts "Generated code:\n" puts entity.code puts "\n" end end
Private Instance Methods
get(url)
click to toggle source
# File lib/rancher/api_discovery.rb, line 53 def get(url) parse_response(RestClient.get(url)) end
parse_response(json)
click to toggle source
# File lib/rancher/api_discovery.rb, line 49 def parse_response(json) JSON.parse(json) end