samg / diffy

Easy Diffing in Ruby
http://rubygems.org/gems/diffy
MIT License
1.27k stars 104 forks source link

Does this work with diff data returned by the GH api? #73

Closed marcamillion closed 8 years ago

marcamillion commented 8 years ago

I love a lot of what I read in the ReadMe. The functionality seems to be almost exactly what I need.

The one thing that's missing is that it seems to focus primarily on raw text as the input.

Would this gem work with the actual diff data returned by Github API?

For instance, here is a sample from the API:

 :patch=>
  "@@ -727,7 +727,6 @@ def require_association_class(class_name)\n         def add_multiple_associated_save_callbacks(association_name)\n           method_name = \"validate_associated_records_for_\#{association_name}\".to_sym\n           define_method(method_name) do\n-            @new_record_before_save = new_record?\n             association = instance_variable_get(\"@\#{association_name}\")\n             if association.respond_to?(:loaded?)\n               if new_record?\n@@ -741,6 +740,7 @@ def add_multiple_associated_save_callbacks(association_name)\n           end\n \n           validate method_name\n+          before_save(\"@new_record_before_save = new_record?; true\")\n \n           after_callback = <<-end_eval\n             association = instance_variable_get(\"@\#{association_name}\")\n@@ -754,9 +754,6 @@ def add_multiple_associated_save_callbacks(association_name)\n               records_to_save.each { |record| association.send(:insert_record, record) }\n               association.send(:construct_sql)   # reconstruct the SQL queries now that we know the owner's id\n             end\n-            \n-            @new_record_before_save = false\n-            true\n           end_eval\n                 \n           # Doesn't use after_save as that would save associations added in after_create/after_update twice"}
]

Can I use this patch data as input and be able to customize it easily per the docs?

marcamillion commented 8 years ago

@samg The advice you gave here - https://github.com/samg/diffy/pull/59#issuecomment-92098614 - seems like it could be exactly what I am looking for, but I would love some more direction.

Do you mind expanding on this a bit, because the specs don't fully show me how to do what I am trying to do.

Thanks.

Edit 1

Would be cool if you could do the same for Split Diffing too -- ideally that's the output I would want.

samg commented 8 years ago

Hi @marcamillion. Yeah, that's not currently a supported feature, but should be fairly easy to hack out if you don't mind getting into the codebase. If you can get your github returned diff data in the format the HTML formatter expects it should work great.