Class: Cisco::ChefUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/cisco_node_utils/cisco_cmn_utils.rb

Class Method Summary collapse

Class Method Details

.generic_prop_set(klass, rlbname, props) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/cisco_node_utils/cisco_cmn_utils.rb', line 60

def ChefUtils.generic_prop_set(klass, rlbname, props)
  props.each do |prop|
    klass.instance_eval {
      # Helper Chef setter method, e.g.:
      #   if @new_resource.foo.nil?
      #     def_prop = @rlb.default_foo
      #     @new_resource.foo(def_prop)
      #   end
      #   current = @rlb.foo
      #   if current != @new_resource.foo
      #     converge_by("update foo '#{current}' => " +
      #                 "'#{@new_resource.foo}'") do
      #       @rlb.foo=(@new_resource.foo)
      #     end
      #   end
      if @new_resource.send(prop).nil?
        def_prop = instance_variable_get(rlbname).send("default_#{prop}")
        # Set resource to default if recipe property is not specified
        @new_resource.send(prop, def_prop)
      end
      current = instance_variable_get(rlbname).send(prop)
      if current != @new_resource.send(prop)
        converge_by("update #{prop} '#{current}' => " +
                    "'#{@new_resource.send(prop)}'") do
          instance_variable_get(rlbname).send("#{prop}=",
                                                   @new_resource.send(prop))
        end
      end
    }
  end
end