class DtcRake::Config

Attributes

app[RW]

Code of application. Guessed from root_dir name if not set.

appbox_artifact_code[RW]

Code of appbox artifact. Guessed from product_code and appbox_version if not set.

appbox_location_code[RW]

Code of appbox location (folder or organization unit). Required.

appbox_meta_artifact_code[RW]

Code of appbox meta artifact. Default value: UU.OS/RUNTIME/APP_BOX.

appbox_territory_code[RW]

Code of territory where the appbox artifact is / should be. Required.

appbox_uarchive[RW]

Path to uarchive with contents of appbox artifact. Default value: nil. If not set, appbox is created with empty content. Relative path is relative to root_dir.

appbox_version[RW]

Appbox version. Read from VERSION file located in the same directory as Rakefile if not set.

colorize[RW]

Print messages in colors. Default value: true.

output_dir[RW]

Name of folder with build products. Default value: target. Relative path is relative to root_dir.

product_code[RW]

Code of product the appbox belongs to. Required.

product_name[RW]

Name of product the appbox belongs to. Required.

root_dir[RW]

Appbox project root folder. Default value: current working directory.

upload_readme[RW]

Upload README.md or README.txt to appbox artifact. Default value: false.

upload_uucloud_descriptor[RW]

Upload uuApp deployment descriptor to appbox artifact. Default value: false.

uucloud_descriptor_path[RW]

Path to uuApp deployment descriptor. Default value: uucloud_descriptor.json.

vendor[RW]

Code of vendor. Guessed from root_dir name if not set.

version_files[RW]

List of files (or glob patterns) determining which files get updated by version:* tasks. Default: none.

Public Class Methods

new() click to toggle source
# File lib/dtc_rake/config.rb, line 15
def initialize
  self.root_dir   = Dir.pwd
  self.output_dir = "target"
  self.colorize   = true
  self.upload_readme = false
  self.appbox_meta_artifact_code = "UU.OS/RUNTIME/APP_BOX"
  self.upload_uucloud_descriptor = false
  self.version_files = []
  guess_vendor_and_app
end

Public Instance Methods

app=(name) click to toggle source
# File lib/dtc_rake/config.rb, line 91
def app=(name)
  @app = name.downcase unless name.nil?
end
appbox_artifact_code=(code) click to toggle source
# File lib/dtc_rake/config.rb, line 108
def appbox_artifact_code=(code)
  env = ENV["DTC_RAKE_APPBOX_ARTIFACT_CODE"]
  # environment variable takes precedence
  @appbox_artifact_code = env.nil? ? code : env
  @appbox_artifact_code
end
appbox_location_code=(code) click to toggle source
# File lib/dtc_rake/config.rb, line 122
def appbox_location_code=(code)
  env = ENV["DTC_RAKE_APPBOX_LOCATION_CODE"]
  # environment variable takes precedence
  @appbox_location_code = env.nil? ? code : env
  @appbox_location_code
end
appbox_meta_artifact_code=(code) click to toggle source
# File lib/dtc_rake/config.rb, line 136
def appbox_meta_artifact_code=(code)
  env = ENV["DTC_RAKE_APPBOX_META_ARTIFACT_CODE"]
  # environment variable takes precedence
  @appbox_meta_artifact_code = env.nil? ? code : env
  @appbox_meta_artifact_code
end
appbox_territory_code=(code) click to toggle source
# File lib/dtc_rake/config.rb, line 150
def appbox_territory_code=(code)
  env = ENV["DTC_RAKE_APPBOX_TERRITORY_CODE"]
  # environment variable takes precedence
  @appbox_territory_code = env.nil? ? code : env
  @appbox_territory_code
end
appbox_uarchive=(path) click to toggle source
# File lib/dtc_rake/config.rb, line 164
def appbox_uarchive=(path)
  env = ENV["DTC_RAKE_APPBOX_UARCHIVE"]
  # environment variable takes precedence
  path = env unless env.nil?

  unless path.nil?
    # File.expand_path converts path to absolute and expands "~" to real user home path
    path = File.expand_path(path)

    if Pathname.new(path).relative?
      @appbox_uarchive = File.join(root_dir, path)
    else
      @appbox_uarchive = path
    end
  end
end
appbox_version=(code) click to toggle source
# File lib/dtc_rake/config.rb, line 196
def appbox_version=(code)
  env = ENV["DTC_RAKE_APPBOX_VERSION"]
  # environment variable takes precedence
  @appbox_version = env.nil? ? code : env
  @appbox_version
end
colorize=(flag) click to toggle source
# File lib/dtc_rake/config.rb, line 213
def colorize=(flag)
  env = ENV["DTC_RAKE_COLORIZE"]
  # environment variable takes precedence
  if env.nil?
    @colorize = flag
  else
    @colorize = to_bool(env)
  end
  @colorize
end
output_dir=(path) click to toggle source
# File lib/dtc_rake/config.rb, line 231
def output_dir=(path)
  env = ENV["DTC_RAKE_OUTPUT_DIR"]
  # environment variable takes precedence
  path = env unless env.nil?

  unless path.nil?
    # File.expand_path converts path to absolute and expands "~" to real user home path
    path = File.expand_path(path)

    if Pathname.new(path).relative?
      @output_dir = File.join(root_dir, path)
    else
      @output_dir = path
    end
  end
end
product_code=(code) click to toggle source
# File lib/dtc_rake/config.rb, line 255
def product_code=(code)
  env = ENV["DTC_RAKE_PRODUCT_CODE"]
  # environment variable takes precedence
  @product_code = env.nil? ? code : env
  @product_code
end
product_name=(name) click to toggle source
# File lib/dtc_rake/config.rb, line 269
def product_name=(name)
  env = ENV["DTC_RAKE_PRODUCT_NAME"]
  # environment variable takes precedence
  @product_name = env.nil? ? name : env
  @product_name
end
root_dir=(path) click to toggle source
# File lib/dtc_rake/config.rb, line 285
def root_dir=(path)
  env = ENV["DTC_RAKE_ROOT_DIR"]
  # environment variable takes precedence
  path = env unless env.nil?

  unless path.nil?
    # File.expand_path converts path to absolute and expands "~" to real user home path
    # If the path is relative, it gets evaluated against to current working directory (Dir.pwd)
    @root_dir = File.expand_path(path)
  end
end
upload_readme=(flag) click to toggle source
# File lib/dtc_rake/config.rb, line 304
def upload_readme=(flag)
  env = ENV["DTC_RAKE_UPLOAD_README"]
  # environment variable takes precedence
  if env.nil?
    @upload_readme = flag
  else
    @upload_readme = to_bool(env)
  end
  @upload_readme
end
upload_uucloud_descriptor=(flag) click to toggle source
# File lib/dtc_rake/config.rb, line 322
def upload_uucloud_descriptor=(flag)
  env = ENV["DTC_RAKE_UPLOAD_UUCLOUD_DESCRIPTOR"]
  # environment variable takes precedence
  if env.nil?
    @upload_uucloud_descriptor = flag
  else
    @upload_uucloud_descriptor = to_bool(env)
  end
  @upload_uucloud_descriptor
end
validate!() click to toggle source
# File lib/dtc_rake/config.rb, line 83
def validate!
  %w(appbox_location_code appbox_territory_code product_code product_name).each do |param|
    if instance_variable_get("@#{param}").nil?
      _error "Required parameter #{param} is not set. Set it within DtcRake.configure in your Rakefile."
    end
  end
end
vendor=(name) click to toggle source
# File lib/dtc_rake/config.rb, line 357
def vendor=(name)
  @vendor = name.downcase unless name.nil?
end
version_files=(list) click to toggle source
# File lib/dtc_rake/config.rb, line 361
def version_files=(list)
  if list.nil?
    @version_files = []
  elsif list.is_a?(Array)
    @version_files = list
  else
    _error "Invalid version_files value - #{list} (#{list})." \
      " Use an array of strings (representing file names or glob patterns)."
  end
end

Private Instance Methods

_error(msg) click to toggle source
# File lib/dtc_rake/config.rb, line 398
def _error(msg)
  # this avoids cycle between dtc_rake/config and dtc_rake/ui
  require "dtc_rake/ui"
  self.class.send(:include, DtcRake::UI) unless self.class.include?(DtcRake::UI)
  error(msg)
end
guess_vendor_and_app() click to toggle source
# File lib/dtc_rake/config.rb, line 378
def guess_vendor_and_app
  env_vendor = ENV["DTC_RAKE_VENDOR"]
  env_app = ENV["DTC_RAKE_APP"]

  if env_vendor.nil? || env_app.nil?
    base_name = File.basename(root_dir)
    if /([^_]+)_([^-]+)-appbox/ =~ base_name
      @vendor = env_vendor.nil? ? $1 : env_vendor
      @app = env_app.nil? ? $2 : env_app
    else
      _error "Appbox root folder (#{base_name}) does not match naming convention <vendor>_<app>-appbox." \
      " Either change the folder name or configure 'vendor' and 'app' within DtcRake.configure in Rakefile." \
      " Or you can set DTC_RAKE_VENDOR and DTC_RAKE_APP environment variables to specify those."
    end
  else
    @vendor = env_vendor
    @app = env_app
  end
end
to_bool(value) click to toggle source
# File lib/dtc_rake/config.rb, line 374
def to_bool(value)
  (value =~ /^true|1|yes$/i) == 0
end