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.
-
#known_omnibus_projects ⇒ Object
Return all known omnibus project names for a product.
-
#omnibus_project(value = nil) ⇒ Object
Set omnibus_project when configured, otherwise fall back to package_name.
-
#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
#known_omnibus_projects ⇒ Object
Return all known omnibus project names for a product
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/mixlib/install/product.rb', line 84 def known_omnibus_projects # iterate through min/max versions for all product names # and collect the name for both versions projects = %w{ 0.0.0 1000.1000.1000 }.collect do |v| @version = v omnibus_project end # remove duplicates and return multiple known names or return the single # project name projects.uniq || projects end |
#omnibus_project(value = nil) ⇒ Object
Set omnibus_project when configured, otherwise fall back to package_name
73 74 75 76 77 78 79 |
# File 'lib/mixlib/install/product.rb', line 73 def omnibus_project(value = nil) if value.nil? @omnibus_project || package_name else @omnibus_project = value end end |
#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
100 101 102 103 104 105 106 |
# File 'lib/mixlib/install/product.rb', line 100 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
115 116 117 |
# File 'lib/mixlib/install/product.rb', line 115 def version_for(version_string) Mixlib::Versioning.parse(version_string) end |