Skip to content
This repository has been archived by the owner on Nov 23, 2020. It is now read-only.

Commit

Permalink
Do inheritance in a clearer way
Browse files Browse the repository at this point in the history
There's no need for code to be repeated in every subclass. The only thing that really needs to change is what the unused field is.

The difference between this and what was there before is that the unused field is stripped from both local and remote whereas in the case of the Load Balancer, it won't be in the local. This doesn't matter though, as there is a test for whether it's present before attemptint to remove it.
  • Loading branch information
annashipman committed Mar 14, 2014
1 parent a2e494b commit d27853c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 46 deletions.
14 changes: 12 additions & 2 deletions lib/vcloud/edge_gateway/configuration_differ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ def diff
end

def stripped_local_config
@local
return @stripped_local unless @stripped_local.nil?
return nil if @local.nil?
@stripped_local = strip_unused_field_from_config(@local)
@stripped_local
end

def stripped_remote_config
@remote
return @stripped_remote unless @stripped_remote.nil?
return nil if @remote.nil?
@stripped_remote = strip_unused_field_from_config(@remote)
@stripped_remote
end

def strip_unused_field_from_config(config)
config
end

end
Expand Down
18 changes: 1 addition & 17 deletions lib/vcloud/edge_gateway/firewall_configuration_differ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,7 @@ module Vcloud
module EdgeGateway
class FirewallConfigurationDiffer < ConfigurationDiffer

def stripped_local_config
return @stripped_local unless @stripped_local.nil?
return nil if @local.nil?
@stripped_local = strip_id_param_from_firewall_rules(@local)
@stripped_local
end

def stripped_remote_config
return @stripped_remote unless @stripped_remote.nil?
return nil if @remote.nil?
@stripped_remote = strip_id_param_from_firewall_rules(@remote)
@stripped_remote
end

private

def strip_id_param_from_firewall_rules(config)
def strip_unused_field_from_config(config)
deep_cloned_config = Marshal.load( Marshal.dump(config) )
if deep_cloned_config.key?(:FirewallRule)
deep_cloned_config[:FirewallRule].each do |firewall_rule|
Expand Down
11 changes: 1 addition & 10 deletions lib/vcloud/edge_gateway/load_balancer_configuration_differ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@ module Vcloud
module EdgeGateway
class LoadBalancerConfigurationDiffer < ConfigurationDiffer

def stripped_remote_config
return @stripped_remote unless @stripped_remote.nil?
return nil if @remote.nil?
@stripped_remote = strip_operational_field_from_config(@remote)
@stripped_remote
end

private

def strip_operational_field_from_config(config)
def strip_unused_field_from_config(config)
deep_cloned_remote_config = Marshal.load( Marshal.dump(config) )
if deep_cloned_remote_config.key?(:Pool)
deep_cloned_remote_config[:Pool].each do |pool_entry|
Expand Down
18 changes: 1 addition & 17 deletions lib/vcloud/edge_gateway/nat_configuration_differ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,7 @@ module Vcloud
module EdgeGateway
class NatConfigurationDiffer < ConfigurationDiffer

def stripped_local_config
return @stripped_local unless @stripped_local.nil?
return nil if @local.nil?
@stripped_local = strip_id_param_from_nat_rules(@local)
@stripped_local
end

def stripped_remote_config
return @stripped_remote unless @stripped_remote.nil?
return nil if @remote.nil?
@stripped_remote = strip_id_param_from_nat_rules(@remote)
@stripped_remote
end

private

def strip_id_param_from_nat_rules(config)
def strip_unused_field_from_config(config)
deep_cloned_config = Marshal.load( Marshal.dump(config) )
if deep_cloned_config.key?(:NatRule)
deep_cloned_config[:NatRule].each do |nat_rule|
Expand Down

0 comments on commit d27853c

Please sign in to comment.