Module: FIR::BuildCommon

Included in:
Util::ClassMethods
Defined in:
lib/fir/util/build_common.rb

Instance Method Summary collapse

Instance Method Details

#convert_hash_to_assignment_string(hash) ⇒ Object

convert { “a” => “1”, “b” => “2” } => “a=‘1’ b=‘2’”



68
69
70
# File 'lib/fir/util/build_common.rb', line 68

def convert_hash_to_assignment_string(hash)
  hash.collect { |k, v| "#{k}='#{v}'" }.join(' ')
end

#initialize_build_common_options(args, options) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/fir/util/build_common.rb', line 6

def initialize_build_common_options(args, options)
  @build_dir     = initialize_build_dir(args)
  @output_path   = initialize_output_path(options)
  @token         = options[:token] || current_token
  @changelog     = options[:changelog].to_s
  @short         = options[:short].to_s
  @proj          = options[:proj].to_s
  @export_qrcode = options[:qrcode]
end

#initialize_build_dir(args) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/fir/util/build_common.rb', line 16

def initialize_build_dir(args)
  if args.first.blank? || !File.exist?(args.first)
    Dir.pwd
  else
    File.absolute_path(args.shift.to_s) # pop the first param
  end
end

#initialize_output_path(options) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/fir/util/build_common.rb', line 24

def initialize_output_path(options)
  if options[:output].blank?
    output_path = "#{@build_dir}/fir_build"
    FileUtils.mkdir_p(output_path) unless File.exist?(output_path)
    output_path
  else
    File.absolute_path(options[:output].to_s)
  end
end

#logger_info_and_run_build_commandObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fir/util/build_common.rb', line 42

def logger_info_and_run_build_command
  puts @build_cmd if $DEBUG

  logger.info 'Building......'
  logger_info_dividing_line

  status = system(@build_cmd)

  unless status
    logger.error 'Build failed'
    exit 1
  end
end

#publish_build_appObject



34
35
36
37
38
39
40
# File 'lib/fir/util/build_common.rb', line 34

def publish_build_app
  logger_info_blank_line
  publish @builded_app_path, short:     @short,
                             changelog: @changelog,
                             token:     @token,
                             qrcode:    @export_qrcode
end

#split_assignment_array_to_hash(arr) ⇒ Object

split [‘a=1’, ‘b=2’] => { ‘a’ => ‘1’, ‘b’ => ‘2’ }



57
58
59
60
61
62
63
64
65
# File 'lib/fir/util/build_common.rb', line 57

def split_assignment_array_to_hash(arr)
  hash = {}
  arr.each do |assignment|
    k, v = assignment.split('=', 2).map(&:strip)
    hash[k] = v
  end

  hash
end