Created
December 30, 2012 12:21
-
-
Save gshutler/4412595 to your computer and use it in GitHub Desktop.
Example of a module before and after logging
This file contains hidden or 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
module Background | |
def self.execute(user) | |
if user.privileged? or transient_condition?(user) | |
something_dangerous(user) | |
end | |
end | |
def self.transient_condition?(user) | |
user.first_name.start_with?(random_character) | |
end | |
end |
This file contains hidden or 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
module Background | |
include Hatchet | |
def self.execute(user) | |
log.info "Entering execute(user:#{user})" | |
do_something_dangerous = false | |
if user.privileged? | |
log.info "#{user} is privileged" | |
do_something_dangerous = true | |
elsif transient_condition?(user) | |
log.info "#{user} satisfied transient condition" | |
do_something_dangerous = true | |
end | |
if do_something_dangerous | |
log.info "Doing something dangerous for #{user}" | |
something_dangerous(user) | |
else | |
log.info "Not doing something dangerous for #{user}" | |
end | |
log.info "Exiting execute(user:#{user})" | |
end | |
def self.transient_condition?(user) | |
log.info "Entering transient_condition?(user:#{user})" | |
character = random_character | |
log.info "Checking if first_name:#{user.first_name} starts with character:#{character}" | |
result = user.first_name.start_with?(random_character) | |
log.info "Exiting transient_condition?(user:#{user}) - return:#{result}" | |
result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment