Skip to content

Commit

Permalink
Add activesupport for Hash#symbolize_keys
Browse files Browse the repository at this point in the history
  • Loading branch information
jdee committed Nov 6, 2017
1 parent cae99dc commit 7a2c23d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/pattern_patch/patch.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require "active_support/core_ext/hash"
require "yaml"

module PatternPatch
Expand All @@ -9,7 +10,7 @@ class Patch

class << self
def from_yaml(path)
hash = YAML.load_file path
hash = YAML.load_file(path).symbolize_keys

# Adjust string fields from YAML

Expand All @@ -34,6 +35,7 @@ def initialize(options = {})

def apply(files, options = {})
offset = options[:offset] || 0
files = [files] if files.kind_of? String

files.each do |path|
modified = Utilities.apply_patch File.read(path),
Expand All @@ -48,6 +50,7 @@ def apply(files, options = {})

def revert(files, options = {})
offset = options[:offset] || 0
files = [files] if files.kind_of? String

files.each do |path|
modified = Utilities.revert_patch File.read(path),
Expand Down
2 changes: 2 additions & 0 deletions pattern_patch.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Gem::Specification.new do |spec|
spec.homepage = 'http://github.com/jdee/pattern_patch'
spec.license = 'MIT'

spec.add_dependency 'activesupport'

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'rake'
Expand Down
8 changes: 4 additions & 4 deletions spec/patch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

expect(File).to receive(:write).with('file.txt', 'xy')

patch.apply ['file.txt']
patch.apply 'file.txt'
end

it 'passes the offset option if present' do
Expand All @@ -60,7 +60,7 @@

expect(File).to receive(:write).with('file.txt', 'x')

patch.apply ['file.txt'], offset: 1
patch.apply 'file.txt', offset: 1
end
end

Expand All @@ -79,7 +79,7 @@

expect(File).to receive(:write).with('file.txt', 'x')

patch.revert ['file.txt']
patch.revert 'file.txt'
end

it 'passes the offset option if present' do
Expand All @@ -97,7 +97,7 @@

expect(File).to receive(:write).with('file.txt', 'x')

patch.revert ['file.txt'], offset: 1
patch.revert 'file.txt', offset: 1
end
end

Expand Down

0 comments on commit 7a2c23d

Please sign in to comment.