pattern_patch 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ff256ce29e8fdaa8bc20bc6bb669e422122dfb1c
4
- data.tar.gz: f07da4e866130406e75dfe1e628267a926da7ea3
2
+ SHA256:
3
+ metadata.gz: dd8fdd5900bc457f4ef68718357106a235b03e9dbbec0bb4b0ae3198631ab1bf
4
+ data.tar.gz: '006809f391325b397e8b2384adf016905df3d457e85b989ab654a7c0a8fbc72e'
5
5
  SHA512:
6
- metadata.gz: 61f887f39ffe1bcfaaa3485a3fa57abf92dbbbafe4f254735ebfb60acc5dfbf29a159675e8cdf3272702841ba36c70983deae0d4b4422526704cf6c44bdf5e2b
7
- data.tar.gz: a463db4f793130b7e49ffe4cad33b9923f80e9131825a7211775dca833bee2b10adb7bf28de6c864ba3205ed8cfbf72fc0fbd3cd731eb4e294629100c1c13858
6
+ metadata.gz: 37f18f695fc3168be2e313aa7e83ea48179e846251067a9dfd60d66ad45d4b94a52472790359ef1202c87f5dbe7cf408c98990878705ece9946e1cbd3591e813
7
+ data.tar.gz: d8520fdc2f6f40e8893e575a3cd35b738992a53edefcada5adfaa414a2aac19cc0ca96e3cf1b30d4aac66cf9b584305b1306487507b4e6d7425f58db5ccc42b6
@@ -0,0 +1,70 @@
1
+ require "active_support/core_ext/hash"
2
+ require "yaml"
3
+
4
+ module PatternPatch
5
+ class Patch
6
+ attr_accessor :regexp
7
+ attr_accessor :text
8
+ attr_accessor :mode
9
+ attr_accessor :global
10
+
11
+ class << self
12
+ def from_yaml(path)
13
+ hash = YAML.load_file(path).symbolize_keys
14
+
15
+ # Adjust string fields from YAML
16
+
17
+ if hash[:regexp].kind_of? String
18
+ hash[:regexp] = /#{hash[:regexp]}/
19
+ end
20
+
21
+ if hash[:mode].kind_of? String
22
+ hash[:mode] = hash[:mode].to_sym
23
+ end
24
+
25
+ new hash
26
+ end
27
+ end
28
+
29
+ def initialize(options = {})
30
+ @regexp = options[:regexp]
31
+ @text = options[:text]
32
+ @mode = options[:mode] || :append
33
+ @global = options[:global].nil? ? false : options[:global]
34
+ end
35
+
36
+ def apply(files, options = {})
37
+ offset = options[:offset] || 0
38
+ files = [files] if files.kind_of? String
39
+
40
+ files.each do |path|
41
+ modified = Utilities.apply_patch File.read(path),
42
+ regexp,
43
+ text,
44
+ global,
45
+ mode,
46
+ offset
47
+ File.write path, modified
48
+ end
49
+ end
50
+
51
+ def revert(files, options = {})
52
+ offset = options[:offset] || 0
53
+ files = [files] if files.kind_of? String
54
+
55
+ files.each do |path|
56
+ modified = Utilities.revert_patch File.read(path),
57
+ regexp,
58
+ text,
59
+ global,
60
+ mode,
61
+ offset
62
+ File.write path, modified
63
+ end
64
+ end
65
+
66
+ def inspect
67
+ "#<PatternPatch::Patch regexp=#{regexp.inspect} text=#{text.inspect} mode=#{mode.inspect} global=#{global.inspect}>"
68
+ end
69
+ end
70
+ end
@@ -1,3 +1,3 @@
1
1
  module PatternPatch
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/pattern_patch.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require "pattern_patch/core_ext"
2
+ require "pattern_patch/patch"
2
3
  require "pattern_patch/utilities"
3
4
  require "pattern_patch/version"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pattern_patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
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-10-15 00:00:00.000000000 Z
11
+ date: 2017-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -98,16 +112,16 @@ dependencies:
98
112
  name: rubocop
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - ">="
115
+ - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '0'
117
+ version: 0.50.0
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - ">="
122
+ - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '0'
124
+ version: 0.50.0
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: simplecov
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -133,6 +147,7 @@ files:
133
147
  - lib/pattern_patch.rb
134
148
  - lib/pattern_patch/core_ext.rb
135
149
  - lib/pattern_patch/core_ext/string.rb
150
+ - lib/pattern_patch/patch.rb
136
151
  - lib/pattern_patch/utilities.rb
137
152
  - lib/pattern_patch/version.rb
138
153
  homepage: http://github.com/jdee/pattern_patch
@@ -155,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
170
  version: '0'
156
171
  requirements: []
157
172
  rubyforge_project:
158
- rubygems_version: 2.6.14
173
+ rubygems_version: 2.7.1
159
174
  signing_key:
160
175
  specification_version: 4
161
176
  summary: Apply and revert pattern-based patches to text files of any kind