end
nil
end
-
- # Executed if method is missing. In this case we are going to catch
- # unqualified property methods for dynamic property setting and getting.
- def method_missing(meth, *args, &block)
- dynamic_methods = self.class.instance_variable_get('@resource_map').keys
- dynamic_methods << :chain
- dynamic_methods << :table
- dynamic_methods << :action
-
- if dynamic_methods.include?(meth.to_sym) then
- if @property_hash[meth.to_sym] then
- return @property_hash[meth.to_sym]
- else
- return nil
- end
- elsif dynamic_methods.include?(meth.to_s.chomp("=").to_sym) then
- debug("Args: #{args}")
- @property_hash[:needs_change] = true
- return true
- end
-
- debug("Dynamic methods: #{dynamic_methods.join(' ')}")
- debug("Method missing: #{meth}. Calling super.")
-
- super
- end
end
:pkttype => "-m pkttype --pkt-type"
}
+ # Create property methods dynamically
+ (@resource_map.keys << :chain << :table << :action).each do |property|
+ define_method "#{property}" do
+ @property_hash[property.to_sym]
+ end
+
+ define_method "#{property}=" do
+ @property_hash[:needs_change] = true
+ end
+ end
+
# This is the order of resources as they appear in iptables-save output,
# we need it to properly parse and apply rules, if the order of resource
# changes between puppet runs, the changed rules will be re-applied again.
:pkttype => "-m pkttype --pkt-type"
}
+ # Create property methods dynamically
+ (@resource_map.keys << :chain << :table << :action).each do |property|
+ define_method "#{property}" do
+ @property_hash[property.to_sym]
+ end
+
+ define_method "#{property}=" do
+ @property_hash[:needs_change] = true
+ end
+ end
+
# This is the order of resources as they appear in iptables-save output,
# we need it to properly parse and apply rules, if the order of resource
# changes between puppet runs, the changed rules will be re-applied again.