Class: Md2site::Init

Inherits:
Object
  • Object
show all
Defined in:
lib/md2site/init.rb

Overview

initサブコマンドクラス

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src_root_dir, mes, verbose) ⇒ Init

初期化

Parameters:

  • src_root_dir (String)

    コピー元ルートディレクトリ

  • mes (Messagex)

    Messagexクラスのインスタンス

  • verbose (Boolean)

    FileUtilsクラスのメソッドのverbose引数に与える値



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/md2site/init.rb', line 31

def initialize(src_root_dir, mes, verbose)
  @mes = mes
  @verbose = verbose
  @src_root_dir = src_root_dir

  @conf_file = CONF_FILE
  @conf_dir = CONF_DIR
  @template_dir = TEMPLATE_DIR
  @root_output_dir = OUTPUT_DIR
  @hs = {
    "rootOutputDir" => @root_output_dir,
    "templateDir" => @template_dir,
    "confDir" => @conf_dir,
    "rootSrcDir" => SRC_DIR,
    "statusFile" => STATUS_FILE,
    "siteFile" => SITE_FILE,
    "settingfile" => SETTING_FILE,
    "dataDir" => DATA_DIR,
    "workDir" => WORK_DIR,
    "materialDir" => MATERIAL_DIR,
    "categoryConfPrefix" => CATEGORY_CONF_PREFIX,
    "defaultTableTampleteFile" => DEFAULT_TABLE_TEMPLATE_FILE,
  }
end

Instance Attribute Details

#conf_fileObject (readonly)

構成ファイルのパス

return [String]



15
16
17
# File 'lib/md2site/init.rb', line 15

def conf_file
  @conf_file
end

#hsObject (readonly)

ハッシュ

return [Hash]



9
10
11
# File 'lib/md2site/init.rb', line 9

def hs
  @hs
end

#template_dirObject (readonly)

テンプレートディレクトリ

return [String]



21
22
23
# File 'lib/md2site/init.rb', line 21

def template_dir
  @template_dir
end

Instance Method Details

#execute_subcommand(option, option_url) ⇒ void

This method returns an undefined value.

サブコマンド実行

Parameters:

  • option (Struct)

    オプションストラクト

  • option_url (Struct)

    URLオプションストラクト



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/md2site/init.rb', line 62

def execute_subcommand(option, option_url)
  root_dir = option.value
  unless File.exist?(root_dir)
    @mes.exc_make_directory(root_dir) { FileUtils.mkdir_p(root_dir, { verbose: @verbose }) }
  end
  absolute_path_root = File.absolute_path(option.value)

  if option_url
    url = %Q(URL=#{option_url.value})
  else
    url = DEFAULT_URL_SETTING
  end

  @hs[KEY_URL] = url

  td = Testdata.new(@src_root_dir, @template_dir, hs)

  copy_all_files(@src_root_dir, @conf_dir, absolute_path_root, @conf_dir)
  testdata_dir_array = td.testdata_dir_array
  testdata_dir_array.map {|dir| copy_all_files(@src_root_dir, dir, absolute_path_root, @conf_dir) }
  template_dir_array = td.template_dir_array
  copy_templatefile(@src_root_dir, template_dir_array, absolute_path_root, @template_dir)
  files = expand_and_write_files(@src_root_dir, @conf_dir, absolute_path_root, [@conf_file], @hs)
  root_output_path = File.join(absolute_path_root, @root_output_dir)
  @mes.exc_make_directory(root_output_path) { FileUtils.mkdir_p(root_output_path, { verbose: @verbose }) }
  @env = Env.new(files[0], @mes, @verbose)
end