Skip to content

Instantly share code, notes, and snippets.

@MarsuperMammal
Created May 6, 2015 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarsuperMammal/6addd6bb1796f2dd0fb4 to your computer and use it in GitHub Desktop.
Save MarsuperMammal/6addd6bb1796f2dd0fb4 to your computer and use it in GitHub Desktop.
unfuck the circular logic
require 'rubytree'
require './bluecat_api.rb'
module Tree
class TreeNode
def as_json(options={})
json_hash = {
"name" => name,
"id" => content[:id],
"type" => content[:type]
}
if has_children?
json_hash["children"] = children
end
return json_hash
end
end
end
module Bluecat
class Tree < Api
attr_accessor :configurations
def build_dns_objects( parent_node )
parent_id = parent_node.content[:id]
items = get_dns_zones (parent_id)
items.each do |zone|
unless zone[:name] =~ /_\w+/
node = ::Tree::TreeNode.new( zone[:name], { :id => zone[:id], :type => zone[:type]})
build_dns_objects(node)
parent_node << node
end
end
end
def build_tree
@configurations = []
items = get_dns_views
items.each do |config|
node = ::Tree::TreeNode.new( config[:name], { :id => config[:id], :type => config[:type]})
build_dns_objects(node)
@configurations << node
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment