Module: Chef::Mixin::Language
- Included in:
- RecipeDefinitionDSLCore, Recipe, Resource
- Defined in:
- lib/chef/mixin/language.rb
Defined Under Namespace
Classes: PlatformDependentValue, PlatformFamilyDependentValue
Instance Method Summary collapse
- #data_bag(bag) ⇒ Object
- #data_bag_item(bag, item) ⇒ Object
-
#platform?(*args) ⇒ Boolean
Given a list of platforms, returns true if the current recipe is being run on a node with that platform, false otherwise.
-
#platform_family?(*args) ⇒ Boolean
Given a list of platform families, returns true if the current recipe is being run on a node within that platform family, false otherwise.
- #search(*args, &block) ⇒ Object
-
#value_for_platform(platform_hash) ⇒ Object
Given a hash similar to the one we use for Platforms, select a value from the hash.
-
#value_for_platform_family(platform_family_hash) ⇒ Object
Given a hash mapping platform families to values, select a value from the hash.
Instance Method Details
#data_bag(bag) ⇒ Object
229 230 231 232 233 234 235 236 |
# File 'lib/chef/mixin/language.rb', line 229 def data_bag(bag) DataBag.validate_name!(bag.to_s) rbag = DataBag.load(bag) rbag.keys rescue Exception Log.error("Failed to list data bag items in data bag: #{bag.inspect}") raise end |
#data_bag_item(bag, item) ⇒ Object
238 239 240 241 242 243 244 245 |
# File 'lib/chef/mixin/language.rb', line 238 def data_bag_item(bag, item) DataBag.validate_name!(bag.to_s) DataBagItem.validate_id!(item) DataBagItem.load(bag, item) rescue Exception Log.error("Failed to load data bag item: #{bag.inspect} #{item.inspect}") raise end |
#platform?(*args) ⇒ Boolean
Given a list of platforms, returns true if the current recipe is being run on a node with that platform, false otherwise.
Parameters
- args
-
A list of platforms. Each platform can be in string or symbol format.
Returns
- true
-
If the current platform is in the list
- false
-
If the current platform is not in the list
120 121 122 123 124 125 126 127 128 |
# File 'lib/chef/mixin/language.rb', line 120 def platform?(*args) has_platform = false args.flatten.each do |platform| has_platform = true if platform.to_s == node[:platform] end has_platform end |
#platform_family?(*args) ⇒ Boolean
Given a list of platform families, returns true if the current recipe is being run on a node within that platform family, false otherwise.
Parameters
- args
-
A list of platform families. Each platform family can be in string or symbol format.
Returns
- true
-
if the current node platform family is in the list.
- false
-
if the current node platform family is not in the list.
206 207 208 209 210 211 212 |
# File 'lib/chef/mixin/language.rb', line 206 def platform_family?(*args) has_pf = false args.flatten.each do |platform_family| has_pf = true if platform_family.to_s == node[:platform_family] end has_pf end |
#search(*args, &block) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/chef/mixin/language.rb', line 214 def search(*args, &block) # If you pass a block, or have at least the start argument, do raw result parsing # # Otherwise, do the iteration for the end user if Kernel.block_given? || args.length >= 4 Chef::Search::Query.new.search(*args, &block) else results = Array.new Chef::Search::Query.new.search(*args) do |o| results << o end results end end |
#value_for_platform(platform_hash) ⇒ Object
Given a hash similar to the one we use for Platforms, select a value from the hash. Supports per platform defaults, along with a single base default. Arrays may be passed as hash keys and will be expanded.
Parameters
- platform_hash
-
A platform-style hash.
Returns
- value
-
Whatever the most specific value of the hash is.
107 108 109 |
# File 'lib/chef/mixin/language.rb', line 107 def value_for_platform(platform_hash) PlatformDependentValue.new(platform_hash).value_for_node(node) end |
#value_for_platform_family(platform_family_hash) ⇒ Object
Given a hash mapping platform families to values, select a value from the hash. Supports a single base default if platform family is not in the map. Arrays may be passed as hash keys and will be expanded.
Parameters
- platform_family_hash
-
A hash in the form { platform_family_name => value }
Returns
- value
-
Whatever the most specific value of the hash is.
193 194 195 |
# File 'lib/chef/mixin/language.rb', line 193 def value_for_platform_family(platform_family_hash) PlatformFamilyDependentValue.new(platform_family_hash).value_for_node(node) end |