Module: Chef::Mixin::Language

Included in:
RecipeDefinitionDSLCore, Recipe, Resource
Defined in:
lib/chef/mixin/language.rb

Defined Under Namespace

Classes: PlatformDependentValue

Instance Method Summary collapse

Instance Method Details

#data_bag(bag) ⇒ Object



145
146
147
148
# File 'lib/chef/mixin/language.rb', line 145

def data_bag(bag)
  rbag = Chef::DataBag.load(bag)
  rbag.keys
end

#data_bag_item(bag, item) ⇒ Object



150
151
152
# File 'lib/chef/mixin/language.rb', line 150

def data_bag_item(bag, item)
  Chef::DataBagItem.load(bag, item)
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

Returns

true

If the current platform is in the list

false

If the current platform is not in the list

Returns:

  • (Boolean)


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 == node[:platform]
  end
  
  has_platform
end

#search(*args, &block) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/chef/mixin/language.rb', line 130

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