Class: GitReviewer::InitOption
- Inherits:
-
Object
- Object
- GitReviewer::InitOption
- Defined in:
- lib/gitreviewer/option/init_option.rb
Instance Attribute Summary collapse
-
#fileExist ⇒ Object
Returns the value of attribute fileExist.
Instance Method Summary collapse
- #check_file_exist ⇒ Object
- #create_default_file ⇒ Object
- #deep_transform_keys_to_strings(value) ⇒ Object
- #execute ⇒ Object
Instance Attribute Details
#fileExist ⇒ Object
Returns the value of attribute fileExist.
9 10 11 |
# File 'lib/gitreviewer/option/init_option.rb', line 9 def fileExist @fileExist end |
Instance Method Details
#check_file_exist ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/gitreviewer/option/init_option.rb', line 21 def check_file_exist file_name = ".gitreviewer.yml" @fileExist = File.exist?(file_name) if @fileExist Printer.yellow "`.gitreviewer.yml` already exists. Please do not init again." exit 1 end end |
#create_default_file ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gitreviewer/option/init_option.rb', line 30 def create_default_file() project_owner = "<project owner>" folder_owner = FolderOwner.new("", "") file_owner = FileOwner.new("", "") config = Configuration.new(project_owner, [folder_owner], [file_owner], [""], [""]) data = config.to_hash data = deep_transform_keys_to_strings(data) yaml = YAML.dump(data) head = "# `.gitreviewer.yml` is used for a git plugin: git-reviewer.\n# For detailed information about git-reviewer, please refer to https://github.com/baochuquan/git-reviewer\n" content = head + yaml File.open('.gitreviewer.yml', 'w') do |file| file.write(content) end Printer.put "`.gitreviewer.yml` created successfully. If you want to customize settings, please edit this file.\n" end |
#deep_transform_keys_to_strings(value) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gitreviewer/option/init_option.rb', line 46 def deep_transform_keys_to_strings(value) case value when Hash value.transform_keys(&:to_s).transform_values { |v| deep_transform_keys_to_strings(v) } when Array value.map { |v| deep_transform_keys_to_strings(v) } else value # 如果既不是哈希也不是数组,直接返回原值 end end |
#execute ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/gitreviewer/option/init_option.rb', line 11 def execute # 判断当前 .gitreviewer 文件是否存在 check_file_exist # 如果不存在,则创建 .gitreviewer.yml if !@fileExist create_default_file end end |