]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
(GH-128) Change method_missing to define_method
authorKen Barber <ken@bob.sh>
Thu, 28 Feb 2013 21:15:02 +0000 (21:15 +0000)
committerKen Barber <ken@bob.sh>
Thu, 28 Feb 2013 21:15:02 +0000 (21:15 +0000)
Previously method_missing was enough to create dynamic methods but Puppet 3.0
broke that functionality. So here we used 'define_method' instead to work
around that.

Signed-off-by: Ken Barber <ken@bob.sh>
lib/puppet/provider/firewall.rb
lib/puppet/provider/firewall/ip6tables.rb
lib/puppet/provider/firewall/iptables.rb

index 0ab16f7a157118cd20c20b3d54df192d76530737..c6b0b10bb132876762daca8484eff4f7fea17a52 100644 (file)
@@ -31,30 +31,4 @@ class Puppet::Provider::Firewall < Puppet::Provider
     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
index 57599206d9bebb7c61c6ec8d49b283454dacc9bd..d681caaf0e0faa2f6662c1d9d50a64de896f9c87 100644 (file)
@@ -56,6 +56,17 @@ Puppet::Type.type(:firewall).provide :ip6tables, :parent => :iptables, :source =
     :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.
index b34e73613279b88ab34cf5a141c7563508e2b5c3..50444142be31dd10b5b22f76650556cf4a9a7565 100644 (file)
@@ -66,6 +66,17 @@ Puppet::Type.type(:firewall).provide :iptables, :parent => Puppet::Provider::Fir
     :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.