pattern_patch 0.2.0 → 0.3.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
2
  SHA256:
3
- metadata.gz: dd8fdd5900bc457f4ef68718357106a235b03e9dbbec0bb4b0ae3198631ab1bf
4
- data.tar.gz: '006809f391325b397e8b2384adf016905df3d457e85b989ab654a7c0a8fbc72e'
3
+ metadata.gz: e6f3d56a8e098394dcb99213f11b443e2f9594f170c18e42bc7b542c66a5ce05
4
+ data.tar.gz: 74ef513114b65d8dc6920d7780abfbbbb0f44434bf904315a5486a662302e944
5
5
  SHA512:
6
- metadata.gz: 37f18f695fc3168be2e313aa7e83ea48179e846251067a9dfd60d66ad45d4b94a52472790359ef1202c87f5dbe7cf408c98990878705ece9946e1cbd3591e813
7
- data.tar.gz: d8520fdc2f6f40e8893e575a3cd35b738992a53edefcada5adfaa414a2aac19cc0ca96e3cf1b30d4aac66cf9b584305b1306487507b4e6d7425f58db5ccc42b6
6
+ metadata.gz: 9d1965026da862449372668c4c3b835203700d30d93e6baf84c2d5a8eccb674d4badb8ed74fbc3bca2f812d1b489668f2b6dcb1a79fab84f323b04afe1c534c5
7
+ data.tar.gz: 043d8424830d6c8cd5ca3893c00c396bf49dafa2f4e425df222d046d04d7d2fa9a75862afd586580998cc4455b57b2495435a8f5060b4d9244e7574a7206168f
@@ -7,6 +7,7 @@ module PatternPatch
7
7
  attr_accessor :text
8
8
  attr_accessor :mode
9
9
  attr_accessor :global
10
+ attr_reader :text_file
10
11
 
11
12
  class << self
12
13
  def from_yaml(path)
@@ -22,17 +23,35 @@ module PatternPatch
22
23
  hash[:mode] = hash[:mode].to_sym
23
24
  end
24
25
 
26
+ if hash[:text_file]
27
+ hash[:text_file] = File.expand_path hash[:text_file], File.dirname(path)
28
+ end
29
+
25
30
  new hash
26
31
  end
27
32
  end
28
33
 
29
34
  def initialize(options = {})
35
+ raise ArgumentError, "text and text_file are mutually exclusive" if options[:text] && options[:text_file]
36
+
30
37
  @regexp = options[:regexp]
31
- @text = options[:text]
38
+ @text_file = options[:text_file]
39
+
40
+ if @text_file
41
+ @text = File.read @text_file
42
+ else
43
+ @text = options[:text]
44
+ end
45
+
32
46
  @mode = options[:mode] || :append
33
47
  @global = options[:global].nil? ? false : options[:global]
34
48
  end
35
49
 
50
+ def text_file=(path)
51
+ @text_file = path
52
+ @text = File.read path if path
53
+ end
54
+
36
55
  def apply(files, options = {})
37
56
  offset = options[:offset] || 0
38
57
  files = [files] if files.kind_of? String
@@ -1,3 +1,3 @@
1
1
  module PatternPatch
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  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.2.0
4
+ version: 0.3.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-11-06 00:00:00.000000000 Z
11
+ date: 2017-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport