Class: Fastlane::Actions::WriteJsonAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::WriteJsonAction
- Defined in:
- lib/fastlane/plugin/json/actions/write_json_action.rb
Class Method Summary collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .details ⇒ Object
- .is_supported?(_platform) ⇒ Boolean
- .print_params(options) ⇒ Object
- .put_error!(message) ⇒ Object
- .return_value ⇒ Object
- .run(params) ⇒ Object
Class Method Details
.authors ⇒ Object
77 78 79 |
# File 'lib/fastlane/plugin/json/actions/write_json_action.rb', line 77 def self. ["Martin Gonzalez"] end |
.available_options ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/fastlane/plugin/json/actions/write_json_action.rb', line 43 def self. [ FastlaneCore::ConfigItem.new(key: :hash, description: "Hash that you want to save as a json file", optional: false, type: Hash, verify_block: proc do |value| UI.user_error!("You must set hash: parameter") unless value && !value.empty? end), FastlaneCore::ConfigItem.new(key: :file_path, description: "Path where you want to save your json", is_string: true, optional: false, verify_block: proc do |value| UI.user_error!("You must set file_path: parameter") unless value && !value.empty? end), FastlaneCore::ConfigItem.new(key: :verbose, description: "verbose", optional: true, type: Boolean) ] end |
.description ⇒ Object
35 36 37 |
# File 'lib/fastlane/plugin/json/actions/write_json_action.rb', line 35 def self.description "Write a json file from a hash at the provided path" end |
.details ⇒ Object
39 40 41 |
# File 'lib/fastlane/plugin/json/actions/write_json_action.rb', line 39 def self.details "Use this action to serialize a hash into a json file in a provided path." end |
.is_supported?(_platform) ⇒ Boolean
81 82 83 |
# File 'lib/fastlane/plugin/json/actions/write_json_action.rb', line 81 def self.is_supported?(_platform) true end |
.print_params(options) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/fastlane/plugin/json/actions/write_json_action.rb', line 66 def self.print_params() table_title = "Params for write_json #{Fastlane::Json::VERSION}" FastlaneCore::PrintTable.print_values(config: , hide_keys: [], title: table_title) end |
.put_error!(message) ⇒ Object
30 31 32 33 |
# File 'lib/fastlane/plugin/json/actions/write_json_action.rb', line 30 def self.put_error!() UI.user_error!() raise StandardError, end |
.return_value ⇒ Object
73 74 75 |
# File 'lib/fastlane/plugin/json/actions/write_json_action.rb', line 73 def self.return_value "Nothing" end |
.run(params) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fastlane/plugin/json/actions/write_json_action.rb', line 8 def self.run(params) hash = params[:hash] file_path = params[:file_path] @is_verbose = params[:verbose] print_params(params) if @is_verbose put_error!("file_path: value cannot be nil or empty") if file_path.nil? || file_path.empty? put_error!("hash: value cannot be nil") if hash.nil? = File.(file_path) file_dir = File.dirname() Dir.mkdir(file_dir) unless File.directory?(file_dir) begin File.open(file_path, "w") do |f| f.write(JSON.pretty_generate(hash)) end rescue put_error!("File at path #{json_path} has invalid content. ❌") end end |