Module: Dapp::Dapp::Dappfile
- Included in:
- Dapp::Dapp
- Defined in:
- lib/dapp/dapp/dappfile.rb
Defined Under Namespace
Modules: Error
Instance Method Summary collapse
- #config ⇒ Object
- #dappfile_exists? ⇒ Boolean
- #download_dappfile_yml_bin(dappfile_yml_bin_path) ⇒ Object
- #expand_path(path, number = 1) ⇒ Object
- #load_dappfile_ruby(dappfile_path) ⇒ Object
- #load_dappfile_yml(dappfile_path) ⇒ Object
Instance Method Details
#config ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dapp/dapp/dappfile.rb', line 28 def config @config ||= begin config = nil dappfile_yml = path("dappfile.yml").to_s dappfile_yaml = path("dappfile.yaml").to_s dappfile_ruby = path("Dappfile").to_s if ENV["DAPP_LOAD_CONFIG_PATH"] config = YAML.load_file ENV["DAPP_LOAD_CONFIG_PATH"] elsif File.exist? dappfile_yml config = load_dappfile_yml(dappfile_yml) elsif File.exist? dappfile_yaml config = load_dappfile_yml(dappfile_yaml) elsif File.exist? dappfile_ruby config = load_dappfile_ruby(dappfile_ruby) else raise ::Dapp::Error::Dapp, code: :dappfile_not_found end if ENV["DAPP_DUMP_CONFIG"] puts "-- DAPP_DUMP_CONFIG BEGIN" puts YAML.dump(config) puts "-- DAPP_DUMP_CONFIG END" end config.tap do config.after_parsing! config.validate! end end # begin end |
#dappfile_exists? ⇒ Boolean
21 22 23 24 25 26 |
# File 'lib/dapp/dapp/dappfile.rb', line 21 def dappfile_exists? File.exist?(path("dappfile.yml")) || File.exist?(path("dappfile.yaml")) || File.exist?(path("Dappfile")) || ENV["DAPP_LOAD_CONFIG_PATH"] end |
#download_dappfile_yml_bin(dappfile_yml_bin_path) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/dapp/dapp/dappfile.rb', line 114 def download_dappfile_yml_bin(dappfile_yml_bin_path) lock("downloader.bin.dappfile-yml", default_timeout: 1800) do return if File.exists? dappfile_yml_bin_path log_process("Downloading dappfile-yml dapp dependency") do location = URI("https://dl.bintray.com/flant/dapp/#{::Dapp::VERSION}/dappfile-yml") tmp_bin_path = File.join(self.class.tmp_base_dir, "dappfile-yml-#{SecureRandom.uuid}") ::Dapp::Downloader.download(location, tmp_bin_path, show_progress: true, progress_titile: dappfile_yml_bin_path) checksum_location = URI("https://dl.bintray.com/flant/dapp/#{::Dapp::VERSION}/dappfile-yml.sha") tmp_bin_checksum_path = tmp_bin_path + ".checksum" ::Dapp::Downloader.download(checksum_location, tmp_bin_checksum_path) if Digest::SHA256.hexdigest(File.read(tmp_bin_path)) != File.read(tmp_bin_checksum_path).strip raise ::Dapp::Error::Dapp, code: :download_failed_bad_dappfile_yml_checksum, data: {url: location.to_s, checksum_url: checksum_location.to_s} end File.chmod(0755, tmp_bin_path) FileUtils.mkdir_p File.dirname(dappfile_yml_bin_path) FileUtils.mv tmp_bin_path, dappfile_yml_bin_path end # log_process end # lock end |
#expand_path(path, number = 1) ⇒ Object
15 16 17 18 19 |
# File 'lib/dapp/dapp/dappfile.rb', line 15 def (path, number = 1) path = File.(path) number.times.each { path = File.dirname(path) } path end |
#load_dappfile_ruby(dappfile_path) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/dapp/dapp/dappfile.rb', line 61 def load_dappfile_ruby(dappfile_path) ::Dapp::Config::Config.new(dapp: self).tap do |config| begin config.instance_eval File.read(dappfile_path), dappfile_path rescue SyntaxError, StandardError => e backtrace = e.backtrace.find { |line| line.start_with?(dappfile_path) } = begin case e when NoMethodError e. =~ /`.*'/ "undefined method #{Regexp.last_match}" when NameError then e.[/.*(?= for)/] else e. end end = "#{backtrace[/.*(?=:in)/]}: #{}" if backtrace raise ::Dapp::Error::Dappfile, code: :incorrect, data: { error: e.class.name, message: } end # begin-rescue end end |
#load_dappfile_yml(dappfile_path) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/dapp/dapp/dappfile.rb', line 83 def load_dappfile_yml(dappfile_path) if dappfile_yml_bin_path = ENV["DAPP_BIN_DAPPFILE_YML"] unless File.exists? dappfile_yml_bin_path raise ::Dapp::Error::Dapp, code: :dappfile_yml_bin_path_not_found, data: {path: dappfile_yml_bin_path} end else dappfile_yml_bin_path = File.join(::Dapp::Dapp.home_dir, "bin", "dappfile-yml", ::Dapp::VERSION, "dappfile-yml") unless File.exists? dappfile_yml_bin_path download_dappfile_yml_bin(dappfile_yml_bin_path) end end cmd_res = shellout "#{dappfile_yml_bin_path} -dappfile #{dappfile_path}" raw_json_response = nil if cmd_res.exitstatus == 0 raw_json_response = cmd_res.stdout elsif cmd_res.exitstatus == 16 raw_json_response = cmd_res.stderr else shellout_cmd_should_succeed! cmd_res end response = JSON.parse(raw_json_response) log_warning(response["warning"]) unless response["warning"].empty? raise ::Dapp::Dapp::Dappfile::Error::DappfileYmlErrorResponse.new(response["error"], response) if response["error"] YAML.load response["dappConfig"] end |