Skip to content

Instantly share code, notes, and snippets.

@sheki
Last active April 5, 2018 19:57
Show Gist options
  • Save sheki/ed610e971b089218caca0c89bfbf7862 to your computer and use it in GitHub Desktop.
Save sheki/ed610e971b089218caca0c89bfbf7862 to your computer and use it in GitHub Desktop.
approximate.rb
class SuperActiveRecord < ActiveRecord
instance_methods.each |name| do .# not exact syntaxa
### IF THIS IS NOT POSSBILE override 10 most use actie record methods like
### new/find/where/find_by/update so on and so forth
original_method = instance_method(name)
define_method(name) do |*args|
check_if_allowed()
original_method.bind(self).call(*args)[[[[
end
end
def check_if_allowed
if PRODUCTION.?
pass
end
callers = caller
check_if_caller_allowed() # by having a whitelist per-model
en
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment