diff --git a/lib/pattern_patch/patch.rb b/lib/pattern_patch/patch.rb index 083e422..aa4e234 100644 --- a/lib/pattern_patch/patch.rb +++ b/lib/pattern_patch/patch.rb @@ -1,3 +1,4 @@ +require "active_support/core_ext/hash" require "yaml" module PatternPatch @@ -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 @@ -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), @@ -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), diff --git a/pattern_patch.gemspec b/pattern_patch.gemspec index 40a4558..db0aea8 100644 --- a/pattern_patch.gemspec +++ b/pattern_patch.gemspec @@ -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' diff --git a/spec/patch_spec.rb b/spec/patch_spec.rb index c25a585..6d66315 100644 --- a/spec/patch_spec.rb +++ b/spec/patch_spec.rb @@ -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 @@ -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 @@ -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 @@ -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