Class: Puppet_X::Coi::Jboss::Functions

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_x/coi/jboss/functions/jboss_to_i.rb,
lib/puppet_x/coi/jboss/functions/jboss_to_s.rb,
lib/puppet_x/coi/jboss/functions/jboss_dirname.rb,
lib/puppet_x/coi/jboss/functions/jboss_to_bool.rb,
lib/puppet_x/coi/jboss/functions/jboss_basename.rb,
lib/puppet_x/coi/jboss/functions/jboss_type_version.rb,
lib/puppet_x/coi/jboss/functions/jboss_short_version.rb

Overview

A custom class that holds custom functions

Class Method Summary collapse

Class Method Details

.jboss_basename(args) ⇒ string|string[]

PRIVATE INTERNAL FUNCTION. Returns the last component of the filename given in file_name

Parameters:

  • args (Array)

    should be only one argument in array

Returns:

  • (string|string[])

    the file name(s)

Raises:

  • (Puppet::ParseError)


9
10
11
12
13
14
15
16
17
# File 'lib/puppet_x/coi/jboss/functions/jboss_basename.rb', line 9

def jboss_basename args
  raise(Puppet::ParseError, "jboss_basename(): Wrong numbers of arguments given (#{args.size} for 1)") if args.size != 1
  input = args[0]
  if input.is_a?(Array)
    input.collect do |a| File.basename(a) end
  else
    File.basename(input)
  end
end

.jboss_dirname(args) ⇒ string|string[]

PRIVATE INTERNAL FUNCTION. Returns the forst component of the filename given in file_name

Parameters:

  • args (Array)

    should be only one argument in array

Returns:

  • (string|string[])

    the file path(s)

Raises:

  • (Puppet::ParseError)


9
10
11
12
13
14
15
16
# File 'lib/puppet_x/coi/jboss/functions/jboss_dirname.rb', line 9

def jboss_dirname args
  raise(Puppet::ParseError, "jboss_dirname(): Wrong numbers of arguments given (#{args.size} for 1)") if args.size != 1
  if args[0].is_a?(Array)
    args[0].collect do |a| File.dirname(a) end
  else
    File.dirname(args[0])
  end
end

.jboss_short_version(args) ⇒ string|string[]

PRIVATE INTERNAL FUNCTION. Return the version of application server

Parameters:

  • args (Array)

    should be only one argument in array

Returns:

  • (string|string[])

    the application server name(s)

Raises:

  • (Puppet::ParseError)


9
10
11
12
13
14
15
16
# File 'lib/puppet_x/coi/jboss/functions/jboss_short_version.rb', line 9

def jboss_short_version args
  raise(Puppet::ParseError, "jboss_short_version(): Wrong number of arguments given (#{args.size} for 1)") if args.size != 1

  version = args[0]
  re = /^(?:[a-z]+-)?(\d+\.\d+)\.\d+(?:\.[A-Za-z]+)?$/
  m = re.match(version)
  if m then m[1] else nil end
end

.jboss_to_bool(args) ⇒ string

PRIVATE INTERNAL FUNCTION. Casts any value to boolean

Parameters:

  • args (Array)

    should be only one argument in array

Returns:

  • (string)

    casted value to boolean



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/puppet_x/coi/jboss/functions/jboss_to_bool.rb', line 9

def jboss_to_bool args
  if args.size != 1
    raise(Puppet::ParseError, "jboss_to_bool(): Wrong number of arguments given (#{args.size} for 1)")
  end
  string = args[0]
  # If string is already Boolean, return it
  if !!string == string
    return string
  end
  string = string.to_s if string.is_a?(Symbol)
  string = string.inspect unless string.is_a?(String)

  # We consider all the yes, no, y, n and so on too ...
  result = case string
    #
    # This is how undef looks like in Puppet ...
    # We yield false in this case.
    #
    when /^$/, '' then false # Empty string will be false ...
    when /^(1|t|y|true|yes)$/  then true
    when /^(0|f|n|false|no)$/  then false
    when /^(undef|undefined)$/ then false # This is not likely to happen ...
    else
      false
  end

  return result
end

.jboss_to_i(args) ⇒ int

PRIVATE INTERNAL FUNCTION. Casts any value to integer

Parameters:

  • args (Array)

    should be only one argument in array

Returns:

  • (int)

    casted value to integer of input value



9
10
11
12
13
14
# File 'lib/puppet_x/coi/jboss/functions/jboss_to_i.rb', line 9

def jboss_to_i args
  if args.size != 1
    raise(Puppet::ParseError, "jboss_to_i(): Wrong number of arguments given (#{args.size} for 1)")
  end
  args[0].to_s.to_i
end

.jboss_to_s(args) ⇒ string

PRIVATE INTERNAL FUNCTION. Casts any value to string

Parameters:

  • args (Array)

    should be only one argument in array

Returns:

  • (string)

    casted value to string



9
10
11
12
13
14
# File 'lib/puppet_x/coi/jboss/functions/jboss_to_s.rb', line 9

def jboss_to_s args
  if args.size != 1
    raise(Puppet::ParseError, "jboss_to_s(): Wrong number of arguments given (#{args.size} for 1)")
  end
  args[0].to_s
end

.jboss_type_version(args) ⇒ string|string[]

PRIVATE INTERNAL FUNCTION. Return type of application server given as input

Parameters:

  • args (Array)

    should be only one argument in array

Returns:

  • (string|string[])

    the application server name

Raises:

  • (Puppet::ParseError)


9
10
11
12
13
14
15
# File 'lib/puppet_x/coi/jboss/functions/jboss_type_version.rb', line 9

def jboss_type_version args
  raise(Puppet::ParseError, "jboss_type_version(): Given invalid number of parameters(#{args.size} instead of 1)") if args.size != 1
  version = args[0]
  re = /^([a-z]+)-(?:\d+\.\d+)\.\d+(?:\.[A-Za-z]+)?$/
  m = re.match(version)
  if m then m[1] else nil end
end