Skip to content

Instantly share code, notes, and snippets.

@kohigh
Created January 3, 2019 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kohigh/c6ee7f650feb85dd5b2e939216e0a148 to your computer and use it in GitHub Desktop.
Save kohigh/c6ee7f650feb85dd5b2e939216e0a148 to your computer and use it in GitHub Desktop.
App initializer and destructor
module App
module Initializer
class << self
include EM::Deferrable
def load_app
#log that app loaded all files and ready to start from this point
succeed
end
end
end
module Destructor
class << self
include EM::Deferrable
def release_resources
#log that app is closing. Think about a way to make this logic be able to differ closing reasons
succeed
end
end
end
class << self
extend Forwardable
def root
@root ||= File.dirname(File.expand_path('..', __FILE__))
end
def environment
@default_env ||= ENV['SMSERVICE_ENV'] || 'development'
end
alias env environment
def_delegator Initializer, :load_app, :init
def_delegator Destructor, :release_resources, :close
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment