Module: Capistrano::Helpers::Base
- Defined in:
- lib/capistrano/helpers/base.rb
Overview
Helper functions for both runit and monit
Instance Method Summary collapse
- #app_env_underscore ⇒ Object
-
#environment ⇒ Object
Automatically sets the environment based on presence of :stage (multistage) :rails_env RAILS_ENV variable;.
-
#run_rake(task) ⇒ Object
Execute a rake taske using the proper env.
- #template_to_s_io(template_file) ⇒ Object
- #user_app_env_underscore ⇒ Object
- #user_app_env_underscore_short ⇒ Object
- #user_app_env_underscore_short_char_safe ⇒ Object
Instance Method Details
#app_env_underscore ⇒ Object
20 21 22 |
# File 'lib/capistrano/helpers/base.rb', line 20 def app_env_underscore "#{fetch(:application)}_#{environment}".squish.downcase.gsub(/[\s|-]/, '_') end |
#environment ⇒ Object
Automatically sets the environment based on presence of :stage (multistage) :rails_env RAILS_ENV variable;
Defaults to “production” if not found
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/capistrano/helpers/base.rb', line 32 def environment # rubocop:disable Metrics/MethodLength if !fetch(:rails_env).nil? fetch(:rails_env) elsif !fetch(:rack_env).nil? fetch(:rack_env) elsif !fetch(:stage).nil? fetch(:stage) else info '---------------------------------------------------------------' info '- Stage, rack or rails environment isn\'t set in -' info '- :stage, :rails_env or :rack_env, defaulting to \'production\' -' info '---------------------------------------------------------------' 'production' end end |
#run_rake(task) ⇒ Object
Execute a rake taske using the proper env. run_rake db:migrate
57 58 59 60 61 62 63 |
# File 'lib/capistrano/helpers/base.rb', line 57 def run_rake(task) within(current_path) do with rails_env: fetch(:rails_env) do execute :rake, "#{task}" end end end |
#template_to_s_io(template_file) ⇒ Object
48 49 50 51 |
# File 'lib/capistrano/helpers/base.rb', line 48 def template_to_s_io(template_file) fail "Cannot find template #{template_file}" unless File.exist?(template_file) StringIO.new(ERB.new(File.read(template_file)).result(binding)) end |
#user_app_env_underscore ⇒ Object
8 9 10 |
# File 'lib/capistrano/helpers/base.rb', line 8 def user_app_env_underscore "#{fetch(:user)}_#{fetch(:application)}_#{environment}".squish.downcase.gsub(/[\s|-]/, '_') end |
#user_app_env_underscore_short ⇒ Object
12 13 14 |
# File 'lib/capistrano/helpers/base.rb', line 12 def user_app_env_underscore_short "#{fetch(:user)[0...1]}_#{environment[0...1]}_#{fetch(:application)}".squish.downcase.gsub(/[\s|-]/, '_') end |
#user_app_env_underscore_short_char_safe ⇒ Object
16 17 18 |
# File 'lib/capistrano/helpers/base.rb', line 16 def user_app_env_underscore_short_char_safe user_app_env_underscore_short.squish.downcase.gsub(/[\s|-]/, '_') end |