Adam Spiers c0e3907ba0 tidy up requires
It's really ugly to have to keep repeating File.dirname(__FILE__),
so we use a temporary variable, even in the case of a single require.
This minimises long "requires" lines and "requires" statements with
needing line-breaks, and should make search-and-replace a bit easier
if we later want to migrate to __dir__ (Ruby >= 2.0) or require_relative.

  http://stackoverflow.com/questions/4333286/ruby-require-vs-require-relative-best-practice-to-workaround-running-in-both

I've deliberately rejected the pattern:

  require File.expand_path('../relative/path', __FILE__)

because it relies on inconsistent semantics and inconsistent
documentation in File.expand_path:

  http://stackoverflow.com/questions/4333286/ruby-require-vs-require-relative-best-practice-to-workaround-running-in-both#comment34147297_4333552
2014-03-25 18:37:50 +00:00

38 lines
888 B
Ruby

this_dir = File.dirname(__FILE__)
require File.expand_path('../resource', this_dir)
require File.expand_path('../mixins/resource_meta', this_dir)
class Pacemaker::Resource::Clone < Pacemaker::Resource
TYPE = 'clone'
register_type TYPE
include Pacemaker::Mixins::Resource::Meta
# FIXME: need to handle params as well as meta
attr_accessor :rsc
def self.attrs_to_copy_from_chef
%w(rsc meta)
end
def definition_string
str = "#{self.class::TYPE} #{name} #{rsc}"
unless meta.empty?
str << continuation_line(meta_string)
end
str
end
def parse_definition
unless definition =~ /^#{self.class::TYPE} (\S+) (\S+)/
raise Pacemaker::CIBObject::DefinitionParseError, \
"Couldn't parse definition '#{definition}'"
end
self.name = $1
self.rsc = $2
self.meta = self.class.extract_hash(definition, 'meta')
end
end