
Previously libraries/pacemaker/mixins/resource_meta.rb had: module Pacemaker class Resource module Meta ... but libraries/pacemaker/resource.rb had: module Pacemaker class Resource < Pacemaker::CIBObject ... This would work fine if libraries/pacemaker/resource.rb was loaded before libraries/pacemaker/mixins/resource_meta.rb, because then Pacemaker::Resource would have Pacemaker::CIBObject as its parent class, and the mixin would simply add the Meta module within the existing Pacemaker::Resource class. However, due to Chef's somewhat erratic method of loading libraries, sometimes it could happen the other way around, in which case Pacemaker::Resource would be initially defined by the mixin with no parent class, and then when resource.rb was loaded, it would attempt to redefine Resource to have a parent class, triggering the error.
31 lines
658 B
Ruby
31 lines
658 B
Ruby
# A mixin for Pacemaker::Resource subclasses which support meta attributes
|
|
# (priority, target-role, is-managed)
|
|
|
|
module Pacemaker
|
|
module Mixins
|
|
module Resource
|
|
module Meta
|
|
def self.included(base)
|
|
base.extend ClassMethods
|
|
end
|
|
|
|
attr_accessor :meta
|
|
|
|
def meta_string
|
|
self.class.meta_string(meta)
|
|
end
|
|
|
|
module ClassMethods
|
|
def meta_string(meta)
|
|
return "" if ! meta or meta.empty?
|
|
"meta " +
|
|
meta.sort.map do |key, value|
|
|
%'#{key}="#{value}"'
|
|
end.join(' ')
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|