Fog::Generators::Compute::VcloudDirector::OrgVdcNetwork
F

Very complex method in #generate_xml

          def generate_xml
            body = Nokogiri::XML::Builder.new do
              attrs = {
                :xmlns => 'http://www.vmware.com/vcloud/v1.5',
                :name  => options[:name]

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

High overall complexity: 214

module Fog
  module Generators
    module Compute
      module VcloudDirector
        # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/types/OrgVdcNetworkType.html

When classes take on too many responsibilities, they grow. A large number of instance variables or methods can make a class hard to understand. Large classes tend to have lower cohesion and higher churn.

Often large classes have methods that do not operate on all of the class state. Identifying the groups of data that are used together can point to seams to split out additional collaborator classes or value objects.

Another trick is to look for repeated prefixes or suffixes in method and variable names, or repeated parameter names, and use them to guide extractions.

Refactorings

Further Reading

There are no issues that match your filters.

module Fog
  module Generators
    module Compute
      module VcloudDirector
        # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/types/OrgVdcNetworkType.html
        class OrgVdcNetwork
          attr_reader :options

          def initialize(options={})
            @options = options
          end

          def generate_xml
            body = Nokogiri::XML::Builder.new do
              attrs = {
                :xmlns => 'http://www.vmware.com/vcloud/v1.5',
                :name  => options[:name]
              }
              OrgVdcNetwork(attrs) {
                Description options[:Description] if options.key?(:Description)
                if configuration = options[:Configuration]
                  Configuration {
                    if ip_scopes = configuration[:IpScopes]
                      IpScopes {
                        if ip_scope = ip_scopes[:IpScope]
                          IpScope {
                            IsInherited  ip_scope[:IsInherited] if ip_scope.key?(:IsInherited)
                            Gateway      ip_scope[:Gateway]     if ip_scope.key?(:Gateway)
                            Netmask      ip_scope[:Netmask]     if ip_scope.key?(:Netmask)
                            Dns1         ip_scope[:Dns1]        if ip_scope.key?(:Dns1)
                            Dns2         ip_scope[:Dns2]        if ip_scope.key?(:Dns2)
                            DnsSuffix    ip_scope[:DnsSuffix]   if ip_scope.key?(:DnsSuffix)
                            IsEnabled    ip_scope[:IsEnabled]   if ip_scope.key?(:IsEnabled)
                            if ip_ranges = ip_scope[:IpRanges]
                              IpRanges {
                                ip_ranges.each do |h|
                                  if h.key?(:IpRange)
                                    IpRange {
                                      StartAddress h[:IpRange][:StartAddress]
                                      EndAddress   h[:IpRange][:EndAddress]
                                    }
                                  end
                                end
                              }
                            end
                          }
                        end
                      }
                    end
                    FenceMode    configuration[:FenceMode]
                    if router_info = configuration[:RouterInfo]
                      RouterInfoType {
                        ExternalIp router_info[:ExternalIp]
                      }
                    end
                  }
                end # Configuration

                if edgegw = options[:EdgeGateway] and configuration[:FenceMode] != 'isolated'
                  EdgeGateway(edgegw)
                elsif options[:Configuration] && options[:Configuration][:FenceMode] == 'isolated'
                  # isolated networks can specify ServiceConfig
                  if sc = options[:ServiceConfig]
                    ServiceConfig {
                      if dhcp = sc[:GatewayDhcpService]
                        IsEnabled dhcp[:IsEnabled] if dhcp[:IsEnabled]
                        if pool = dhcp[:Pool]
                          IsEnabled        pool[:IsEnabled]
                          DefaultLeaseTime pool[:DefaultLeaseTime]
                          MaxLeaseTime     pool[:MaxLeaseTime]
                          LowIpAddress     pool[:LowIpAddress]
                          HighIpAddress    pool[:HighIpAddress]
                        end
                      end
                    }
                  end
                end

                IsShared       options[:IsShared] if options.key?(:IsShared)

              }
            end.to_xml
          end
        end
      end
    end
  end
end

Size

Lines of code
81