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, :install_path, :omnibus_project, ]
Instance Method Summary collapse
-
#default_value_for(prop) ⇒ Object
Return the default values for DSL properties.
-
#initialize(&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(&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
#default_value_for(prop) ⇒ Object
Return the default values for DSL properties
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/mixlib/install/product.rb', line 74 def default_value_for(prop) case prop when :install_path "/opt/#{package_name}" when :omnibus_project package_name else nil end end |
#known_omnibus_projects ⇒ Object
Return all known omnibus project names for a product
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/mixlib/install/product.rb', line 88 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.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/mixlib/install/product.rb', line 49 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 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
104 105 106 107 108 109 110 |
# File 'lib/mixlib/install/product.rb', line 104 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
119 120 121 |
# File 'lib/mixlib/install/product.rb', line 119 def version_for(version_string) Mixlib::Versioning.parse(version_string) end |