module PatternPatch::Methods

Attributes

patch_dir[RW]

@!attribute patch_dir Set this to conveniently load patches from a common folder with the patch method. @return [String] Path to a directory for use with patch

Public Instance Methods

patch(name) click to toggle source

Loads a patch from the patch_dir @param name [#to_s] Name of a patch to load from the patch_dir @return [Patch] A patch loaded from the patch_dir @raise [ConfigurationError] If patch_dir is nil or is not a valid directory path

# File lib/pattern_patch.rb, line 47
def patch(name)
  raise ConfigurationError, "patch_dir has not been set" if patch_dir.nil?
  raise ConfigurationError, "patch_dir #{patch_dir} is not a directory" unless Dir.exist?(patch_dir)

  Patch.from_yaml File.join(patch_dir, "#{name}.yml")
end
patch_config() { |self| ... } click to toggle source

Useful to configure PatternPatch without using the class (PatternPatch.patch_dir=), ivar (@patch_dir) or explicit setter (self.patch_dir=).

include PatternPatch::Methods
patch_config do |c|
  c.patch_dir = 'lib/assets/patches'
  c.trim_mode = '<>'
end

or

include PatternPatch::Methods
patch_config.patch_dir = 'lib/assets/patches'
patch_config.trim_mode = '<>'

@yield self if block_given? @return self or return value of block

# File lib/pattern_patch.rb, line 72
def patch_config(&block)
  if block_given?
    yield self
  else
    self
  end
end