-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Search and compare tokens using hash lookups
- Loading branch information
Showing
9 changed files
with
71 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Changit | ||
class ConfigMerger | ||
def initialize(src_config, target_config) | ||
@src = src_config | ||
@target = target_config | ||
end | ||
|
||
def merge | ||
src_lexer = Lexer.new(@src) | ||
src_token_hash = src_lexer.token_hash | ||
|
||
target_lexer = Lexer.new(@target) | ||
target_token_hash = target_lexer.token_hash | ||
|
||
if target_token_hash.empty? | ||
target_lexer = src_lexer | ||
else | ||
target_token_hash.each do |k, v| | ||
if src_token_hash[k] | ||
target_token_hash[k].merge!(src_token_hash[k]) | ||
end | ||
end | ||
|
||
config_difference = src_token_hash.dup.delete_if { |k, _| target_token_hash.key?(k) } | ||
target_token_hash.merge!(config_difference) | ||
target_lexer.reconstruct_tokens_from_hash! | ||
end | ||
|
||
target_lexer | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Changit | ||
VERSION='0.2.0' | ||
VERSION='0.2.2' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,11 @@ | |
class ConfigWriterTest < Minitest::Test | ||
def test_write_to_existing_file | ||
writer = config_writer | ||
expected = Changit::ConfigMerger.new(writer.config, File.read(writer.config_files.first)).merge.to_s | ||
|
||
writer.write | ||
|
||
assert writer.config == File.read(writer.config_files.first) | ||
assert expected == File.read(writer.config_files.first) | ||
end | ||
|
||
def test_write_to_empty_file | ||
|
@@ -21,8 +23,9 @@ def test_write_to_empty_file | |
|
||
def config_writer | ||
config = "[user]\n\tname = testname\n\temail = [email protected]\n[core]\n\teditor = vim\n[color]\n\tui = true\n[rebase]\n\tautosquash = true\n".freeze | ||
|
||
# this creates an actual file in /tmp you should remove it if you want to | ||
config_files = [File.new("/tmp/config1237879867", 'w')] | ||
config_files = [File.new("/tmp/config1237879867", 'a')] | ||
|
||
Changit::ConfigWriter.new(config, config_files) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters