Module: EasyType::Parameter::ClassMethods

Defined in:
lib/easy_type/parameter.rb

Instance Method Summary collapse

Instance Method Details

#after_apply(&block) ⇒ Object

a property callback that alows you to do certain actions after the resource is actualy created or modified.

Examples:


newproperty(:password) do
  before_apply do
    sql(so somthing we need to do before)
  end
end

Parameters:

  • block (Method)

    The code to be run before creating or modifying a resource. Although the code customary returns just a string that is appended to the command, it can do anything that is deemed nesceccary.

See Also:



96
97
98
# File 'lib/easy_type/parameter.rb', line 96

def after_apply(&block)
  define_method(:after_apply, &block) if block
end

#after_create(&block) ⇒ Object

a property callback that alows you to do certain actions after the resource is actualy created.

Examples:


newproperty(:password) do
  after_create do
    sql(so somthing we need to after the resource is created)
  end
end

Parameters:

  • block (Method)

    The code to be run before creating or modifying a resource. Although the code customary returns just a string that is appended to the command, it can do anything that is deemed nesceccary.

See Also:



144
145
146
# File 'lib/easy_type/parameter.rb', line 144

def after_create(&block)
  define_method(:after_create, &block) if block
end

#after_destroy(&block) ⇒ Object

a property callback that allows you to do certain actions after the resource is actualy destroyed.

Examples:


newproperty(:password) do
  after_destroy do
    # Do something after the type destroy has been called
  end
end

Parameters:

  • block (Method)

    The code to be run before creating or modifying a resource. Although the code customary returns just a string that is appended to the command, it can do anything that is deemed nesceccary.



245
246
247
# File 'lib/easy_type/parameter.rb', line 245

def after_destroy(&block)
  define_method(:after_destroy, &block) if block
end

#after_modify(&block) ⇒ Object

a property callback that alows you to do certain actions after the resource is actualy modfied.

Examples:


newproperty(:password) do
  after_modify do
    sql(so somthing we need to do after modifying the resource)
  end
end

Parameters:

  • block (Method)

    The code to be run before creating or modifying a resource. Although the code customary returns just a string that is appended to the command, it can do anything that is deemed nesceccary.



188
189
190
# File 'lib/easy_type/parameter.rb', line 188

def after_modify(&block)
  define_method(:after_modify, &block) if block
end

#before_apply(&block) ⇒ Object

a property callback that alows you to do certain actions before the resource is actualy created or modified.

Examples:


newproperty(:password) do
  before_apply do
    sql(so somthing we need to do before)
  end
end

Parameters:

  • block (Method)

    The code to be run before creating or modifying a resource. Although the code customary returns just a string that is appended to the command, it can do anything that is deemed nesceccary.

See Also:



72
73
74
# File 'lib/easy_type/parameter.rb', line 72

def before_apply(&block)
  define_method(:before_apply, &block) if block
end

#before_create(&block) ⇒ Object

a property callback that alows you to do certain actions before the resource is actualy created.

Examples:


newproperty(:password) do
  before_create do
    sql(so somthing we need to do before)
  end
end

Parameters:

  • block (Method)

    The code to be run before creating or modifying a resource. Although the code customary returns just a string that is appended to the command, it can do anything that is deemed nesceccary.

See Also:



120
121
122
# File 'lib/easy_type/parameter.rb', line 120

def before_create(&block)
  define_method(:before_create, &block) if block
end

#before_destroy(&block) ⇒ Object

is actualy destroyed.

Examples:


newproperty(:password) do
  before_destroy do
    # we need to do before destroying the resource
  end
end

Parameters:

  • block (Method)

    The code to be run before destroying a resource.



207
208
209
# File 'lib/easy_type/parameter.rb', line 207

def before_destroy(&block)
  define_method(:before_destroy, &block) if block
end

#before_modify(&block) ⇒ Object

a property callback that alows you to do certain actions before the resource is actualy modfied.

Examples:


newproperty(:password) do
  before_modify do
    sql(so somthing we need to do before modifying the resource)
  end
end

Parameters:

  • block (Method)

    The code to be run before creating or modifying a resource. Although the code customary returns just a string that is appended to the command, it can do anything that is deemed nesceccary.

See Also:



168
169
170
# File 'lib/easy_type/parameter.rb', line 168

def before_modify(&block)
  define_method(:before_modify, &block) if block
end

#called_before(method_name) ⇒ Object



263
264
265
# File 'lib/easy_type/parameter.rb', line 263

def called_before(method_name)
  method_defined? method_name
end

#coerce(value) ⇒ Object

Basic implementation for coercing a value to the correct type.



252
253
254
# File 'lib/easy_type/parameter.rb', line 252

def coerce(value)
  value
end

#data_type(_type_string) ⇒ Object

This method is needed to support legacy puppet versions which do not support munging in Puppet::ResourceApi. It returns nil.



26
27
28
# File 'lib/easy_type/parameter.rb', line 26

def data_type(_type_string)
  nil
end

#fail_if_competing_method_definedObject



257
258
259
260
261
# File 'lib/easy_type/parameter.rb', line 257

def fail_if_competing_method_defined
  %w(on_create on_modify).each do |method_name|
    raise "method #{method_name} can not coexist with on_apply. Use one or the other" if called_before(method_name)
  end
end

#on_apply(&block) ⇒ Object

retuns the string needed to modify this specific property of a defined type

Examples:


newproperty(:password) do
  on_apply do
    "identified by #{resource[:password]}"
  end
end

Parameters:

  • block (Method)

    The code to be run on creating or modifying a resource. Although the code customary returns just a string that is appended to the command, it can do anything that is deemed nesceccary.

See Also:



47
48
49
50
# File 'lib/easy_type/parameter.rb', line 47

def on_apply(&block)
  fail_if_competing_method_defined
  define_method(:on_apply, &block) if block
end

#on_create(&block) ⇒ Object

retuns the string needed to create this specific property of a defined type. This method is ONLY called when the resource is created. It is not allowed to have both an ‘on_apply` and a `on_create` definition on the type.

Examples:


newproperty(:password) do
  on_create do
    "identified by #{resource[:password]}"
  end
end

Parameters:

  • block (Method)

    The code to be run on creating a resource. Although the code customary returns just a string that is appended to the command, it can do anything that is deemed nesceccary.

See Also:



286
287
288
# File 'lib/easy_type/parameter.rb', line 286

def on_create(&block)
  define_method(:on_create, &block) if block
end

#on_destroy(&block) ⇒ Object

a property callback that allows you to do certain actionsin the destroy sequence

Examples:


newproperty(:password) do
  on_destroy do
    # do something
  end
end

Parameters:

  • block (Method)

    The code to be run when destroying a resource.



225
226
227
# File 'lib/easy_type/parameter.rb', line 225

def on_destroy(&block)
  define_method(:on_destroy, &block) if block
end

#on_modify(&block) ⇒ Object

retuns the string needed to modify this specific property of a defined type. This method is ONLY called when the resource is modified. It is not allowed to have both an ‘on_apply` and a `on_destroy` definition on the type.

Examples:


newproperty(:password) do
  on_modify do
    "identified by #{resource[:password]}"
  end
end

Parameters:

  • block (Method)

    The code to be run modifying a resource. Although the code customary returns just a string that is appended to the command, it can do anything that is deemed nesceccary.

See Also:



309
310
311
# File 'lib/easy_type/parameter.rb', line 309

def on_modify(&block)
  define_method(:on_modify, &block) if block
end

#to_translate_to_resource(&block) ⇒ Object

maps a raw resource to retuns the string needed to modify this specific property of a type

Examples:


newproperty(:password) do
  map do
   "identified by #{resource[:password]}"
  end
end

Parameters:

  • block (Method)

    The code to be run to pick a part of the raw_hash and use it as the value of this parameter or property.



327
328
329
330
# File 'lib/easy_type/parameter.rb', line 327

def to_translate_to_resource(&block)
  eigenclass = class << self; self; end
  eigenclass.send(:define_method, :translate_to_resource, &block)
end