Module: Gct::FileBase
- Defined in:
- lib/gct/file_base.rb
Class Attribute Summary collapse
-
.path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
- .config_path ⇒ Object
- .exist_root ⇒ Object
- .get_config(key) ⇒ Object
- .initialize(path) ⇒ Object
- .read_version ⇒ Object
- .root_err ⇒ Object
- .set_config(key, value) ⇒ Object
- .tmp_path ⇒ Object
- .version_path ⇒ Object
- .write_version_message(verison, name, branch) ⇒ Object
- .yaml_read(key) ⇒ Object
- .yaml_read_map(path, key) ⇒ Object
- .yaml_write(key, value) ⇒ Object
- .yaml_write_map(path, content) ⇒ Object
Class Attribute Details
.path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/gct/file_base.rb', line 4 def path @path end |
Class Method Details
.config_path ⇒ Object
84 85 86 |
# File 'lib/gct/file_base.rb', line 84 def config_path "#{Generator::GctFile.config_file_path}" end |
.exist_root ⇒ Object
96 97 98 99 |
# File 'lib/gct/file_base.rb', line 96 def exist_root root_exist = File.exist?(Generator::GctFile.root_folder_path) root_exist end |
.get_config(key) ⇒ Object
72 73 74 75 76 |
# File 'lib/gct/file_base.rb', line 72 def get_config(key) root_err @path = config_path yaml_read(key) end |
.initialize(path) ⇒ Object
6 7 8 |
# File 'lib/gct/file_base.rb', line 6 def initialize(path) @path = path end |
.read_version ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/gct/file_base.rb', line 10 def read_version path = version_path if !File.exist?(path) return nil end config_map = YAML.load(File.open(path, "r")) config_map end |
.root_err ⇒ Object
101 102 103 |
# File 'lib/gct/file_base.rb', line 101 def root_err raise "请先运行命令:gct setup".red if !exist_root end |
.set_config(key, value) ⇒ Object
78 79 80 81 82 |
# File 'lib/gct/file_base.rb', line 78 def set_config(key, value) root_err @path = config_path yaml_write(key, value) end |
.tmp_path ⇒ Object
92 93 94 |
# File 'lib/gct/file_base.rb', line 92 def tmp_path "#{Generator::GctFile.temp_folder_path}" end |
.version_path ⇒ Object
88 89 90 |
# File 'lib/gct/file_base.rb', line 88 def version_path "#{Generator::GctFile.temp_folder_path}/version" end |
.write_version_message(verison, name, branch) ⇒ Object
19 20 21 22 23 |
# File 'lib/gct/file_base.rb', line 19 def (verison, name, branch) yaml_path = "#{Generator::GctFile.temp_folder_path}/version" content_map = {"version" => verison, "name" => name, "branch" => branch} yaml_write_map(yaml_path, content_map) end |
.yaml_read(key) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/gct/file_base.rb', line 61 def yaml_read(key) begin yaml_file = YAML.load(File.open(@path, "r")) if yaml_file yaml_file[key] end rescue IOError => e raise e. end end |
.yaml_read_map(path, key) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gct/file_base.rb', line 50 def yaml_read_map(path, key) begin yaml_file = YAML.load(File.open(path, "r")) if yaml_file yaml_file[key] end rescue IOError => e raise e. end end |
.yaml_write(key, value) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gct/file_base.rb', line 25 def yaml_write(key, value) begin config_map = YAML.load(File.open(@path, "r")) config_map = Hash.new() if !config_map config_map[key] = value yaml_file = File.open(@path, "w") YAML::dump(config_map, yaml_file) rescue IOError => e raise e. ensure yaml_file.close unless yaml_file.nil? end end |
.yaml_write_map(path, content) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/gct/file_base.rb', line 39 def yaml_write_map(path, content) begin yaml_file = File.open(path, "w") YAML::dump(content, yaml_file) rescue IOError => e raise e. ensure yaml_file.close unless yaml_file.nil? end end |