Module: PatternPatch::Methods

Extended by:
Forwardable
Included in:
PatternPatch
Defined in:
lib/pattern_patch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#patch_dirString

Set this to conveniently load patches from a common folder with the patch method.

Returns:

  • (String)

    Path to a directory for use with patch



27
28
29
# File 'lib/pattern_patch.rb', line 27

def patch_dir
  @patch_dir
end

#safe_levelObject?

Set the default safe level to use with ERb. This is the same as the value of PatternPatch.safe_level.

Returns:

  • (Object, nil)

    The current default safe level for ERb



33
# File 'lib/pattern_patch.rb', line 33

def_delegator "PatternPatch", :safe_level, :safe_level

#trim_modeString?

Set the default trim mode to use with ERb. This is the same as the value of PatternPatch.trim_mode.

Returns:

  • (String, nil)

    The current default trim mode for ERb



40
# File 'lib/pattern_patch.rb', line 40

def_delegator "PatternPatch", :trim_mode, :trim_mode

Instance Method Details

#patch(name) ⇒ Patch

Loads a patch from the patch_dir

Parameters:

  • name (#to_s)

    Name of a patch to load from the patch_dir

Returns:

  • (Patch)

    A patch loaded from the patch_dir

Raises:



47
48
49
50
51
52
# 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 { ... } ⇒ Object

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 = '<>'

Yields:

  • self if block_given?

Returns:

  • self or return value of block



72
73
74
75
76
77
78
# File 'lib/pattern_patch.rb', line 72

def patch_config(&block)
  if block_given?
    yield self
  else
    self
  end
end