class Chef::RunList::RunListItem
Constants
- FALSE_FRIEND
- QUALIFIED_RECIPE
- QUALIFIED_ROLE
- VERSIONED_UNQUALIFIED_RECIPE
Attributes
name[R]
type[R]
version[R]
Public Class Methods
new(item)
click to toggle source
# File lib/chef/run_list/run_list_item.rb, line 28 def initialize(item) @version = nil case item when Hash assert_hash_is_valid_run_list_item!(item) @type = (item["type"] || item[:type]).to_sym @name = item["name"] || item[:name] if item.has_key?("version") || item.has_key?(:version) @version = item["version"] || item[:version] end when String if match = QUALIFIED_RECIPE.match(item) # recipe[recipe_name] # recipe[recipe_name@1.0.0] @type = :recipe @name = match[1] @version = match[3] if match[3] elsif match = QUALIFIED_ROLE.match(item) # role[role_name] @type = :role @name = match[1] elsif match = VERSIONED_UNQUALIFIED_RECIPE.match(item) # recipe_name@1.0.0 @type = :recipe @name = match[1] @version = match[3] if match[3] elsif match = FALSE_FRIEND.match(item) # Recipe[recipe_name] # roles[role_name] name = match[1] raise ArgumentError, "Unable to create #{self.class} from #{item.class}:#{item.inspect}: must be recipe[#{name}] or role[#{name}]" else # recipe_name @type = :recipe @name = item end else raise ArgumentError, "Unable to create #{self.class} from #{item.class}:#{item.inspect}: must be a Hash or String" end end
Public Instance Methods
==(other)
click to toggle source
# File lib/chef/run_list/run_list_item.rb, line 82 def ==(other) if other.kind_of?(String) to_s == other.to_s else other.respond_to?(:type) && other.respond_to?(:name) && other.respond_to?(:version) && other.type == @type && other.name == @name && other.version == @version end end
assert_hash_is_valid_run_list_item!(item)
click to toggle source
# File lib/chef/run_list/run_list_item.rb, line 90 def assert_hash_is_valid_run_list_item!(item) unless (item.key?("type") || item.key?(:type)) && (item.key?("name") || item.key?(:name)) raise ArgumentError, "Initializing a #{self.class} from a hash requires that it have a 'type' and 'name' key" end end
recipe?()
click to toggle source
# File lib/chef/run_list/run_list_item.rb, line 78 def recipe? @type == :recipe end
role?()
click to toggle source
# File lib/chef/run_list/run_list_item.rb, line 74 def role? @type == :role end
to_s()
click to toggle source
# File lib/chef/run_list/run_list_item.rb, line 70 def to_s "#{@type}[#{@name}#{@version ? "@#{@version}" : ""}]" end