pattern_patch 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb0842afd6861b0575ba1aec38ae58f7b63634b40b0701e6a203f6657bfe5b30
4
- data.tar.gz: 4f75f07d932d25c2072453a08267ca277db019f1960bc1eee415e9e154efb089
3
+ metadata.gz: 9dde903ead1bfdf40adb3e6f7de2b55b0ff3050629c2d1a65083cfd23dbf1020
4
+ data.tar.gz: eb9ae2b3e4422d23a14c8c95af20c01741795b78aa381155d5bd3b448fe62c8b
5
5
  SHA512:
6
- metadata.gz: 2b46b2c0340cb8d37976d28cd753a0f124bbd37d80816f97a9599fb216bc6df03bdbfa98e76323889246edd77d3342c9be722e473d4a0c1d1e2d34f8b57ff281
7
- data.tar.gz: ac9a4e6bc36cb2b03282c988aeb6cf2a4de7ba2e304e99723e1d91575d7b2e2d5d1e13c6c9a81ac8244af01bec00d52e96bd7f5452362e209c9184e95a1f0ea4
6
+ metadata.gz: 4da2db665c24915148a3e05f84d07cd6fa4492f1d8ea8e668bbe40c1dbd451c341b3007b5ac607a008437f3bbbaa48f9afc56cab7773d7d37c0b40223b3d986a
7
+ data.tar.gz: 40e803e6235a46468a8f26df86deecb06b5a3de262c3007e7ab3480a8535839d015358d5c408f5dd97d2126e6c996aa2070cbaaded7a23888671764f808d87da
@@ -123,12 +123,17 @@ module PatternPatch
123
123
  # @param options [Hash] Options for applying the patch.
124
124
  # @option options [Binding] :binding (nil) A Binding object to use when rendering ERB
125
125
  # @option options [Integer] :offset (0) Offset in characters
126
+ # @option options [Object, nil] :safe_level (PatternPatch.safe_level) A valid value for $SAFE for use with ERb
127
+ # @option options [String] :trim_mode (PatternPatch.trim_mode) A valid ERb trim mode
126
128
  # @raise [ArgumentError] In case of invalid mode (other than :append, :prepend, :replace)
127
129
  def apply(files, options = {})
128
130
  offset = options[:offset] || 0
129
131
  files = [files] if files.kind_of? String
130
132
 
131
- patch_text = ERB.new(text).result options[:binding]
133
+ safe_level = options[:safe_level] || PatternPatch.safe_level
134
+ trim_mode = options[:trim_mode] || PatternPatch.trim_mode
135
+
136
+ patch_text = ERB.new(text, safe_level, trim_mode).result options[:binding]
132
137
 
133
138
  files.each do |path|
134
139
  modified = Utilities.apply_patch File.read(path),
@@ -150,12 +155,17 @@ module PatternPatch
150
155
  # @param options [Hash] Options for applying the patch.
151
156
  # @option options [Binding] :binding (nil) A Binding object to use when rendering ERB
152
157
  # @option options [Integer] :offset (0) Offset in characters
158
+ # @option options [Object, nil] :safe_level (PatternPatch.safe_level) A valid value for $SAFE for use with ERb
159
+ # @option options [String] :trim_mode (PatternPatch.trim_mode) A valid ERb trim mode
153
160
  # @raise [ArgumentError] In case of invalid mode (other than :append or :prepend)
154
161
  def revert(files, options = {})
155
162
  offset = options[:offset] || 0
156
163
  files = [files] if files.kind_of? String
157
164
 
158
- patch_text = ERB.new(text).result options[:binding]
165
+ safe_level = options[:safe_level] || PatternPatch.safe_level
166
+ trim_mode = options[:trim_mode] || PatternPatch.trim_mode
167
+
168
+ patch_text = ERB.new(text, safe_level, trim_mode).result options[:binding]
159
169
 
160
170
  files.each do |path|
161
171
  modified = Utilities.revert_patch File.read(path),
@@ -1,3 +1,3 @@
1
1
  module PatternPatch
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
3
3
  end
data/lib/pattern_patch.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "forwardable"
1
2
  require "pattern_patch/core_ext"
2
3
  require "pattern_patch/patch"
3
4
  require "pattern_patch/utilities"
@@ -8,6 +9,8 @@ require "pattern_patch/version"
8
9
  #
9
10
  # @author Jimmy Dee (https://github.com/jdee)
10
11
  module PatternPatch
12
+ extend Forwardable
13
+
11
14
  # Generic exception class for PatternPatch exceptions
12
15
  class Error < RuntimeError; end
13
16
 
@@ -15,12 +18,28 @@ module PatternPatch
15
18
  class ConfigurationError < Error; end
16
19
 
17
20
  module Methods
21
+ extend Forwardable
22
+
18
23
  # @!attribute patch_dir
19
24
  # Set this to conveniently load patches from a common folder with
20
25
  # the patch method.
21
26
  # @return [String] Path to a directory for use with patch
22
27
  attr_accessor :patch_dir
23
28
 
29
+ # @!attribute safe_level
30
+ # Set the default safe level to use with ERb. This is the same as the value
31
+ # of PatternPatch.safe_level.
32
+ # @return [Object, nil] The current default safe level for ERb
33
+ def_delegator "PatternPatch", :safe_level, :safe_level
34
+ def_delegator "PatternPatch", :safe_level=, :safe_level=
35
+
36
+ # @!attribute trim_mode
37
+ # Set the default trim mode to use with ERb. This is the same as the value
38
+ # of PatternPatch.trim_mode.
39
+ # @return [String, nil] The current default trim mode for ERb
40
+ def_delegator "PatternPatch", :trim_mode, :trim_mode
41
+ def_delegator "PatternPatch", :trim_mode=, :trim_mode=
42
+
24
43
  # Loads a patch from the patch_dir
25
44
  # @param name [#to_s] Name of a patch to load from the patch_dir
26
45
  # @return [Patch] A patch loaded from the patch_dir
@@ -32,5 +51,17 @@ module PatternPatch
32
51
  end
33
52
  end
34
53
 
54
+ class << self
55
+ # @!attribute safe_level
56
+ # The default safe level to use with ERb. Defaults to nil.
57
+ # @return [Object, nil] The current default safe level for ERb
58
+ attr_accessor :safe_level
59
+
60
+ # @!attribute trim_mode
61
+ # The default trim mode to use with ERb. Defaults to nil.
62
+ # @return [String, nil] The current default trim mode for ERb
63
+ attr_accessor :trim_mode
64
+ end
65
+
35
66
  extend Methods
36
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pattern_patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Dee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-15 00:00:00.000000000 Z
11
+ date: 2017-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport