class Rebi::InitService

Attributes

env_data[R]
env_name[R]
stage[R]
stage_name[R]

Public Class Methods

new(stage_name, env_name) click to toggle source
# File lib/rebi/init_service.rb, line 9
def initialize stage_name, env_name
  if config.app_name.blank?
    config.app_name = get_appname
  end
  @stage_name = stage_name
  @env_name = env_name
  config.data[:stages] ||= {}.with_indifferent_access

  begin
    @stage = config.stage stage_name
    raise "Already exists" if @stage.keys.include? env_name
  rescue Rebi::Error::ConfigNotFound
    config.data[:stages][stage_name] = {}.with_indifferent_access
  end

  config.data[:stages][stage_name].merge!({
    env_name => ConfigEnvironment::DEFAULT_CONFIG.clone
  }.with_indifferent_access)

  @env_data = config.data[:stages][stage_name][env_name]
end

Public Instance Methods

config() click to toggle source
# File lib/rebi/init_service.rb, line 31
def config
  Rebi.config
end
default_envname() click to toggle source
# File lib/rebi/init_service.rb, line 74
def default_envname
  "#{env_name}-#{stage_name}"
end
eb() click to toggle source
# File lib/rebi/init_service.rb, line 35
def eb
  @eb ||= Rebi.eb
end
execute() click to toggle source
# File lib/rebi/init_service.rb, line 39
def execute
  env_data.reverse_merge!({name: get_envname})
  env_data[:solution_stack_name] = get_solution_stack
  config.push_to_file
end
get_appname() click to toggle source
# File lib/rebi/init_service.rb, line 45
def get_appname
  app_name = nil
  if (apps = eb.applications).present?
    idx = -1
    while idx < 0 || idx > apps.count
      apps.each.with_index do |app, idx|
        log "#{idx + 1}: #{app}"
      end
      log "0: Create new application"
      idx = ask_for_integer "Select application:"
    end
    app_name = idx > 0 ? apps[idx - 1] : nil
  end

  if app_name.blank?
    app_name = ask_for_string "Enter application name:"
  end

  app_name
end
get_envname() click to toggle source
# File lib/rebi/init_service.rb, line 66
def get_envname
  name = ask_for_string "Enter environment name(Default: #{default_envname}):"
  name = name.chomp.gsub(/\s+/, "")

  name = name.present? ? name : default_envname
  name
end
get_solution_stack() click to toggle source
# File lib/rebi/init_service.rb, line 78
def get_solution_stack
  idx = 0
  platform = nil
  version = nil
  while idx <= 0 || idx > eb.platforms.count
    eb.platforms.each.with_index do |pl, idx|
      log "#{idx + 1}: #{pl}"
    end
    idx = ask_for_integer "Select platform:"
  end

  platform = eb.platforms[idx - 1]
  versions = eb.versions_by_platform platform
  idx = versions.count <= 1 ? 1 : 0

  while idx <=0 || idx > versions.count
    versions.each.with_index do |ver, idx|
      log "#{idx + 1}: #{ver}"
    end
    idx = ask_for_integer "Select version:"
  end

  version = versions[idx - 1]

  eb.get_solution_stack platform, version
end
log_label() click to toggle source
# File lib/rebi/init_service.rb, line 105
def log_label
  ""
end