Class: Mixlib::Install::Product

Inherits:
Object
  • Object
show all
Defined in:
lib/mixlib/install/product.rb

Constant Summary collapse

DSL_PROPERTIES =
[
  :config_file,
  :ctl_command,
  :package_name,
  :product_name,
]

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Product

Returns a new instance of Product.



23
24
25
# File 'lib/mixlib/install/product.rb', line 23

def initialize(&block)
  instance_eval(&block)
end

Instance Method Details

#propString

DSL methods can receive either a String or a Proc to calculate the value of the property later on based on the version. We error out if we get both the String and Proc, and we return the value of the property if we do not receive anything.

Parameters:

  • prop_string (String)

    value to be set in String form

  • block (Proc)

    value to be set in Proc form

Returns:

  • (String)

    value of the property



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/mixlib/install/product.rb', line 47

DSL_PROPERTIES.each do |prop|
  define_method prop do |prop_string = nil, &block|
    if block.nil?
      if prop_string.nil?
        value = instance_variable_get("@#{prop}".to_sym)
        return nil if value.nil?

        if value.is_a? String
          value
        else
          value.call(version_for(version))
        end
      else
        instance_variable_set("@#{prop}".to_sym, prop_string)
      end
    else
      raise "Can not use String and Proc at the same time for #{prop}." if !prop_string.nil?
      instance_variable_set("@#{prop}".to_sym, block)
    end
  end
end

#version(value = nil) ⇒ Object

Sets or retrieves the version for the product. This is used later when we are reading the value of a property if a Proc is specified



73
74
75
76
77
78
79
# File 'lib/mixlib/install/product.rb', line 73

def version(value = nil)
  if value.nil?
    @version
  else
    @version = value
  end
end

#version_for(version_string) ⇒ Mixlib::Version

Helper method to convert versions from String to Mixlib::Version

Parameters:

  • version_string (String)

    value to be set in String form

Returns:

  • (Mixlib::Version)


88
89
90
# File 'lib/mixlib/install/product.rb', line 88

def version_for(version_string)
  Mixlib::Versioning.parse(version_string)
end