1515# See the License for the specific language governing permissions and
1616# limitations under the License.
1717
18+ require 'chef/cookbook/metadata/version'
19+
1820class Chef
1921 class RunList
2022 class RunListItem
21- QUALIFIED_RECIPE = %r{^recipe\[ ([^\] ]+)\] $}
23+ QUALIFIED_RECIPE = %r{^recipe\[ ([^\] , ]+)(,( #{ Chef :: Cookbook :: Metadata :: Version :: PATTERN } ))? \] $}
2224 QUALIFIED_ROLE = %r{^role\[ ([^\] ]+)\] $}
2325
24- attr_reader :name
26+ attr_reader :name , :type , :version
2527
26- attr_reader :type
2728
2829 def initialize ( item )
30+ @version = nil
2931 case item
3032 when Hash
3133 assert_hash_is_valid_run_list_item! ( item )
3234 @type = ( item [ 'type' ] || item [ :type ] ) . to_sym
3335 @name = item [ 'name' ] || item [ :name ]
36+ if ( item . has_key? ( 'version' ) || item . has_key? ( :version ) )
37+ @version = item [ 'version' ] || item [ :version ]
38+ end
3439 when String
3540 if match = QUALIFIED_RECIPE . match ( item )
3641 @type = :recipe
3742 @name = match [ 1 ]
43+ @version = match [ 3 ] if match [ 3 ]
3844 elsif match = QUALIFIED_ROLE . match ( item )
3945 @type = :role
4046 @name = match [ 1 ]
@@ -48,7 +54,7 @@ def initialize(item)
4854 end
4955
5056 def to_s
51- "#{ @type } [#{ @name } ]"
57+ "#{ @type } [#{ @name } #{ @version ? ", #{ @version } " : "" } ]"
5258 end
5359
5460 def role?
@@ -63,7 +69,7 @@ def ==(other)
6369 if other . kind_of? ( String )
6470 self . to_s == other . to_s
6571 else
66- other . respond_to? ( :type ) && other . respond_to? ( :name ) && other . type == @type && other . name == @name
72+ other . respond_to? ( :type ) && other . respond_to? ( :name ) && other . respond_to? ( :version ) && other . type == @type && other . name == @name && other . version == @version
6773 end
6874 end
6975
0 commit comments