Top Level Namespace

Defined Under Namespace

Modules: Poise

Instance Method Summary collapse

Instance Method Details

#Poise(options = {}) ⇒ Object

Callable form to allow passing in options: include Poise(ParentResource) include Poise(parent: ParentResource) include Poise(container: true)



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/poise.rb', line 37

def Poise(options={})
  # Allow passing a class as a shortcut
  if options.is_a?(Class)
    options = {parent: options}
  end

  # Create a new anonymous module
  mod = Module.new

  # Fake the name.
  mod.define_singleton_method(:name) do
    super() || 'Poise'
  end

  mod.define_singleton_method(:included) do |klass|
    super(klass)
    # Pull in the main helper to cover most of the needed logic.
    klass.class_exec { include Poise }
    # Set the defined_in values as needed.
    klass.poise_defined!(caller)
    # Resource-specific options.
    if klass < Chef::Resource
      klass.poise_subresource(options[:parent], options[:parent_optional], options[:parent_auto]) if options[:parent]
      klass.poise_subresource_container(options[:container_namespace]) if options[:container]
      klass.poise_fused if options[:fused]
      klass.poise_inversion(options[:inversion_options_resource]) if options[:inversion]
    end
    # Provider-specific options.
    if klass < Chef::Provider
      klass.poise_inversion(options[:inversion], options[:inversion_attribute]) if options[:inversion]
    end
  end

  mod
end