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

- (Group) initialize

Returns a new instance of Group



13
14
15
# File 'lib/easy_type/group.rb', line 13

def initialize
	@content = {}
end

Instance Method Details

- (Group) add(group_name, parameter_or_property)

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 grouo 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



39
40
41
42
43
# File 'lib/easy_type/group.rb', line 39

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

- (Array) contents_for(group_name)

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



25
26
27
# File 'lib/easy_type/group.rb', line 25

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

- (Symbol) group_for(parameter_or_property)

returns the group name for a given parameter or property. If the group deosn'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



53
54
55
56
57
58
# File 'lib/easy_type/group.rb', line 53

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

- (Boolean) include?(group_name)

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.



66
67
68
# File 'lib/easy_type/group.rb', line 66

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

- (Boolean) include_property?(parameter_or_property)

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)


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

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