Module: EasyType::Type::ClassMethods

Defined in:
lib/easy_type/type.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) define_os_command_method(method_or_command)



116
117
118
119
120
121
122
# File 'lib/easy_type/type.rb', line 116

def define_os_command_method(method_or_command)
	eigenclass = class << self; self; end
	eigenclass.send(:define_method, method_or_command) do | *args|
		command = args.dup.unshift(method_or_command) 
		Puppet::Util::Execution.execute( command)
	end
end

- (Group) group(group_name = :default, &block)

define a group of parameters. A group means a change in one of it's members all the information in the group is added tot the command

Examples:

group(:name) do # name is optional
	property :a
	property :b
end

Parameters:

  • group_name (Symbol) (defaults to: :default) —

    the group name to use. A group name must be unique within a type

Returns:

  • (Group) —

    the defined group



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
# File 'lib/easy_type/type.rb', line 41

def group(group_name = :default, &block)
	include EasyType::FileIncluder

  @group_name = group_name # make it global
	@groups ||= EasyType::Group.new


	alias :orig_parameter :parameter
	alias :orig_property :property

  def parameter(parameter_name)
  	process_group_entry(include_file("puppet/type/#{name}/#{parameter_name}"))
  end

  def property(property_name)
  	process_group_entry(include_file("puppet/type/#{name}/#{property_name}"))
  end

  def process_group_entry(entry)
  	@groups.add(name,entry)
  end

	yield if block

	alias :parameter :orig_parameter
	alias :property :orig_property
end

- (Group) groups

Return the groups the type contains

Returns:

  • (Group) —

    All defined groups



73
74
75
76
# File 'lib/easy_type/type.rb', line 73

def groups
	@groups ||= EasyType::Group.new
	@groups
end

- (Object) on_create(&block)

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.



138
139
140
# File 'lib/easy_type/type.rb', line 138

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

- (Object) on_destroy(&block)

end

Parameters:

  • block (Method) —

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



156
157
158
# File 'lib/easy_type/type.rb', line 156

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

- (Object) on_modify(&block)

end

Parameters:

  • block (Method) —

    The code to be run on 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.



174
175
176
# File 'lib/easy_type/type.rb', line 174

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

- (Object) parameter(parameter_name) Also known as: property

Parameters:

  • parameter_name (Symbol) —

    the base name of the parameter



86
87
88
# File 'lib/easy_type/type.rb', line 86

def parameter(parameter_name)
	process_group_entry(include_file("puppet/type/#{name}/#{parameter_name}"))
end

- (Object) process_group_entry(entry)



59
60
61
# File 'lib/easy_type/type.rb', line 59

def process_group_entry(entry)
	@groups.add(name,entry)
end

- (Object) set_command(method_or_command)

Parameters:

  • method_or_command (Symbol) —

    method or os command name



105
106
107
108
109
110
111
112
113
# File 'lib/easy_type/type.rb', line 105

def set_command(method_or_command)
	method_or_command = method_or_command.to_s if RUBY_VERSION == "1.8.7"
	unless methods.include?(method_or_command)
		define_os_command_method(method_or_command)
	end
	define_method(:command) do | *args |
		self.class.send(method_or_command, *args)
	end
end

- (Object) to_get_raw_resources(&block)

end

Parameters:

  • block (Method) —

    The code to be run to fetch the raw resource information from the system.



191
192
193
194
# File 'lib/easy_type/type.rb', line 191

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