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 +4 -4
- data/lib/pattern_patch/patch.rb +12 -2
- data/lib/pattern_patch/version.rb +1 -1
- data/lib/pattern_patch.rb +31 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dde903ead1bfdf40adb3e6f7de2b55b0ff3050629c2d1a65083cfd23dbf1020
|
4
|
+
data.tar.gz: eb9ae2b3e4422d23a14c8c95af20c01741795b78aa381155d5bd3b448fe62c8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4da2db665c24915148a3e05f84d07cd6fa4492f1d8ea8e668bbe40c1dbd451c341b3007b5ac607a008437f3bbbaa48f9afc56cab7773d7d37c0b40223b3d986a
|
7
|
+
data.tar.gz: 40e803e6235a46468a8f26df86deecb06b5a3de262c3007e7ab3480a8535839d015358d5c408f5dd97d2126e6c996aa2070cbaaded7a23888671764f808d87da
|
data/lib/pattern_patch/patch.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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),
|
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.
|
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-
|
11
|
+
date: 2017-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|