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, :product_key, :package_name, :product_name, :install_path, :omnibus_project, :github_repo, :downloads_product_page_url, ]
Instance Method Summary collapse
-
#default_value_for(prop) ⇒ Object
Return the default values for DSL properties.
-
#initialize(key, &block) ⇒ Product
constructor
A new instance of Product.
-
#known_omnibus_projects ⇒ Object
Return all known omnibus project names for a 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(key, &block) ⇒ Product
Returns a new instance of Product.
24 25 26 27 |
# File 'lib/mixlib/install/product.rb', line 24 def initialize(key, &block) @product_key = key instance_eval(&block) end |
Instance Method Details
#default_value_for(prop) ⇒ Object
Return the default values for DSL properties
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/mixlib/install/product.rb', line 79 def default_value_for(prop) case prop when :install_path "/opt/#{package_name}" when :omnibus_project package_name when :downloads_product_page_url "#{Mixlib::Install::Dist::DOWNLOADS_PAGE}/#{product_key}" when :github_repo "#{Mixlib::Install::Dist::GITHUB_ORG}/#{product_key}" else nil end end |
#known_omnibus_projects ⇒ Object
Return all known omnibus project names for a product
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/mixlib/install/product.rb', line 97 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 |
#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.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mixlib/install/product.rb', line 54 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 default_value_for(prop) if value.nil? if value.is_a?(String) || value.is_a?(Symbol) 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
113 114 115 116 117 118 119 |
# File 'lib/mixlib/install/product.rb', line 113 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
128 129 130 |
# File 'lib/mixlib/install/product.rb', line 128 def version_for(version_string) Mixlib::Versioning.parse(version_string) end |