Class: Chef::RunList::RunListItem
- Defined in:
- lib/chef/run_list/run_list_item.rb
Constant Summary collapse
- QUALIFIED_RECIPE =
%r{^recipe\[([^\]@]+)(@([0-9]+(\.[0-9]+){1,2}))?\]$}
- QUALIFIED_ROLE =
%r{^role\[([^\]]+)\]$}
- VERSIONED_UNQUALIFIED_RECIPE =
%r{^([^@]+)(@([0-9]+(\.[0-9]+){1,2}))$}
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #assert_hash_is_valid_run_list_item!(item) ⇒ Object
-
#initialize(item) ⇒ RunListItem
constructor
A new instance of RunListItem.
- #recipe? ⇒ Boolean
- #role? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(item) ⇒ RunListItem
Returns a new instance of RunListItem.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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[[email protected]] @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) # [email protected] @type = :recipe @name = match[1] @version = match[3] if match[3] 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 |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
25 26 27 |
# File 'lib/chef/run_list/run_list_item.rb', line 25 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
25 26 27 |
# File 'lib/chef/run_list/run_list_item.rb', line 25 def type @type end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
25 26 27 |
# File 'lib/chef/run_list/run_list_item.rb', line 25 def version @version end |
Instance Method Details
#==(other) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/chef/run_list/run_list_item.rb', line 76 def ==(other) if other.kind_of?(String) self.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) ⇒ Object
84 85 86 87 88 |
# File 'lib/chef/run_list/run_list_item.rb', line 84 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? ⇒ Boolean
72 73 74 |
# File 'lib/chef/run_list/run_list_item.rb', line 72 def recipe? @type == :recipe end |
#role? ⇒ Boolean
68 69 70 |
# File 'lib/chef/run_list/run_list_item.rb', line 68 def role? @type == :role end |
#to_s ⇒ Object
64 65 66 |
# File 'lib/chef/run_list/run_list_item.rb', line 64 def to_s "#{@type}[#{@name}#{@version ? "@#{@version}" :""}]" end |