Class: EasyType::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_type/group.rb

Overview

A [Group] is a definition of a set of [Parameter] and/or [Property] classes. When you add a [Property] or a [Parameter] to a [Group], you specify that whenever one of the properties is changed, all the ‘on_modify` methods of all parameters and properties are called.

This is a mechanism to ensure an ‘on_update` or `on_create` always is syntacticaly correct and has all the information needed.

Instance Method Summary collapse

Constructor Details

#initializeGroup

Returns a new instance of Group.



18
19
20
# File 'lib/easy_type/group.rb', line 18

def initialize
  @content = {}
end

Instance Method Details

#add(group_name, parameter_or_property) ⇒ Group

Add a parameter or a propert to a group. The may or may not exists. If it doesn’t exist, it will be created. The name of a group is just for identification purpose’s. It doesn’t have any other meaning.

Parameters:

  • group_name (String)

    this is the name of the group.

  • parameter_or_property (Puppet::Parameter)

    this is the specified parameter.

Returns:

Raises:

  • (Puppet::Error)

    When the group doesn’t exist



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

def add(group_name, parameter_or_property)
  group = ensure_group(group_name)
  group << parameter_or_property
  group
end

#contents_for(group_name) ⇒ Array

Get all parameters and properties from the specified group name. If the group doesn’t exist raise an exception

Parameters:

  • group_name (String)

    this is the name of the group.

Returns:

  • (Array)

    an Array of parameters and properties

Raises:

  • (Puppet::Error)

    When the group doesn’t exist



30
31
32
33
34
# File 'lib/easy_type/group.rb', line 30

def contents_for(group_name)
  @content.fetch(group_name) do
    fail "easy_type: No group defined with name #{group_name}"
  end
end

#group_for(parameter_or_property) ⇒ Symbol

returns the group name for a given parameter or property. If the group doesn’t exist, it will raise an error

Parameters:

  • parameter_or_property (Puppet::Parameter)

    this is the specified parameter.

Returns:

  • (Symbol)

    the group name

Raises:

  • (Puppet::Error)

    When the group doesn’t exist



62
63
64
65
66
67
# File 'lib/easy_type/group.rb', line 62

def group_for(parameter_or_property)
  @content.each_pair do |key, value|
    return key if value.include?(parameter_or_property)
  end
  fail "easy_type: #{parameter_or_property} not found in any group"
end

#include?(group_name) ⇒ Boolean

Returns true if the group exists

Parameters:

  • group_name (String)

    this is the name of the group.

Returns:

  • (Boolean)

    true if the group exists. False if the group doesn’t exist.



76
77
78
# File 'lib/easy_type/group.rb', line 76

def include?(group_name)
  @content.keys.include?(group_name)
end

#include_property?(parameter_or_property) ⇒ Boolean

Returns true if the paremeter or property is included in any existing group

Parameters:

  • parameter_or_property (Puppet::Parameter)

    this is the specified parameter.

Returns:

  • (Boolean)


88
89
90
# File 'lib/easy_type/group.rb', line 88

def include_property?(parameter_or_property)
  @content.values.flatten.include?(parameter_or_property)
end