Skip to content

Instantly share code, notes, and snippets.

@DmytroVasin
Last active February 24, 2019 13:28
Show Gist options
  • Save DmytroVasin/78fd084a49950d0f177a8ae1f0b82f46 to your computer and use it in GitHub Desktop.
Save DmytroVasin/78fd084a49950d0f177a8ae1f0b82f46 to your computer and use it in GitHub Desktop.
module RuboCop
module Cop
module CustomCops
class TimecopReplacerCop < Cop
# ...
def autocorrect(arg_pair)
date_string = eval(arg_pair.value.source).strftime('%Y-%m-%dT%H:%M:%S%z')
new_source = String.new("freezed_time: '#{date_string}'")
->(corrector) do
corrector.insert_before(arg_pair.source_range, new_source)
corrector.remove(arg_pair.source_range)
end
end
# ...
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment