Class: Mixlib::Install::Product
- Inherits:
-
Object
- Object
- Mixlib::Install::Product
- Defined in:
- lib/mixlib/install/product.rb
Constant Summary collapse
- DSL_PROPERTIES =
[ :config_file, :ctl_command, :package_name, :product_name, ]
Instance Method Summary collapse
-
#initialize(&block) ⇒ Product
constructor
A new instance of Product.
-
#prop ⇒ String
DSL methods can receive either a String or a Proc to calculate the value of the property later on based on the version.
-
#version(value = nil) ⇒ Object
Sets or retrieves the version for the product.
-
#version_for(version_string) ⇒ Mixlib::Version
Helper method to convert versions from String to Mixlib::Version.
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
#prop ⇒ String
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.
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
88 89 90 |
# File 'lib/mixlib/install/product.rb', line 88 def version_for(version_string) Mixlib::Versioning.parse(version_string) end |