Module: Ansible::Ruby::Modules::FreeForm

Included in:
Command, Include_vars, Meta, Raw, Script, Set_fact, Shell
Defined in:
lib/ansible/ruby/modules/free_form.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/ansible/ruby/modules/free_form.rb', line 9

def included(base)
  klass_name = base.name.demodulize.underscore
  base.validates :free_form,
                 presence: { message: "Argument directly after #{klass_name} e.g. #{klass_name}(arg) cannot be blank" }
  base.validates :free_form,
                 type: {
                   type: String,
                   message: "#{klass_name}(%{value}), %{value} is expected to be a String but was a %{type}"
                 }
end

Instance Method Details

#to_hObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ansible/ruby/modules/free_form.rb', line 21

def to_h
  result = super
  # base module will always have 1 key that is the module
  module_key = result.keys[0]
  args = result[module_key]
  free_form_arg = args.delete :free_form
  result = {
    module_key => free_form_arg
  }
  result[:args] = args if args.any?
  result
end