Created
May 6, 2015 18:58
-
-
Save MarsuperMammal/6addd6bb1796f2dd0fb4 to your computer and use it in GitHub Desktop.
unfuck the circular logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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