lib/kakine/security_rule.rb in kakine-0.4.0 vs lib/kakine/security_rule.rb in kakine-0.5.0
- old
+ new
@@ -1,9 +1,11 @@
module Kakine
class SecurityRule
- attr_reader :id, :direction, :protocol, :port_range_max, :port_range_min, :remote_ip, :remote_group, :ethertype
+ ATTRIBUTES = %i(direction protocol port_range_max port_range_min remote_ip remote_group ethertype).freeze
+ attr_reader :id, *ATTRIBUTES
+
def initialize(rule, tenant_name, sg_name)
@tenant_name = tenant_name
@sg_name = sg_name
rule.each do|k,v|
@@ -12,11 +14,11 @@
@port_range_min, @port_range_max = *convert_port_format(rule)
end
def ==(target_sg)
- %i(@direction @protocol @port_range_max @port_range_min @remote_ip @remote_group @ethertype).all? do |val|
- self.instance_variable_get(val) == target_sg.instance_variable_get(val)
+ ATTRIBUTES.all? do |attr|
+ self.public_send(attr) == target_sg.public_send(attr)
end
end
def convert_port_format(rule)
unless format = port?(rule) || icmp?(rule) || range?(rule)