Class: Chefdore::Magic
- Inherits:
-
Object
- Object
- Chefdore::Magic
- Defined in:
- lib/chefdore/utils.rb
Class Method Summary collapse
- .convert(opts = {}) ⇒ Object
- .convert_attr(opts = {}) ⇒ Object
- .convert_run_list(opts = {}) ⇒ Object
Class Method Details
.convert(opts = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/chefdore/utils.rb', line 41 def self.convert(opts = {}) json = opts[:json] ? opts[:json] : fail("You must pass some JSON in :json opt") cli = opts[:cli] ? opts[:cli] : fail("You must pass the CLI in :cli opt") klass = Chef::JSONCompat.from_json(json) rl = klass.run_list da = klass.default_attributes oa = klass.override_attributes convert_attr(cli: cli, value: da) convert_attr(cli: cli, value: oa, prefix: "override") convert_run_list(cli: cli, run_list: rl) end |
.convert_attr(opts = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/chefdore/utils.rb', line 18 def self.convert_attr(opts = {}) value = opts[:value] prefix = opts[:prefix] ? opts[:prefix] : "default" path = opts[:path] ? opts[:path] : [] cli = opts[:cli] ? opts[:cli] : Chefdore::Cli.new #puts "INFO :: #{value.inspect} (#{value.class}) -- #{prefix} -- #{path}" if value.is_a?(Hash) value.each do |subkey, subval| convert_attr(opts.merge(value: subval, path: path+[subkey])) end elsif value.is_a?(Array) && cli.[:append_arrays] puts "#{prefix}#{path.map{|p| "[#{p.inspect}]"}.join('')} = #{Array.new.inspect}" value.each do |x| puts "#{prefix}#{path.map{|p| "[#{p.inspect}]"}.join('')} << #{x.inspect}" end else puts "#{prefix}#{path.map{|p| "[#{p.inspect}]"}.join('')} = #{value.inspect}" end end |
.convert_run_list(opts = {}) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/chefdore/utils.rb', line 8 def self.convert_run_list(opts = {}) rl = opts[:run_list] ? opts[:run_list] : [] cli = opts[:cli] ? opts[:cli] : Chefdore::Cli.new rl.recipes.each do |x| puts "include_recipe #{x.inspect}" end end |