Class: Fastlane::Actions::MergeJsonsAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::MergeJsonsAction
- Defined in:
- lib/fastlane/plugin/json_auth/actions/merge_jsons_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
- .write_hash_at(output_path, hash) ⇒ Object
Class Method Details
.authors ⇒ Object
95 96 97 |
# File 'lib/fastlane/plugin/json_auth/actions/merge_jsons_action.rb', line 95 def self. ["Martin Gonzalez"] end |
.available_options ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fastlane/plugin/json_auth/actions/merge_jsons_action.rb', line 62 def self. [ FastlaneCore::ConfigItem.new(key: :jsons_paths, description: "Array of json files paths", type: Array, optional: false, verify_block: proc do |value| UI.user_error!("You must set jsons_paths") unless value && !value.empty? end), FastlaneCore::ConfigItem.new(key: :output_path, description: "Output path where result will be saved", type: String, optional: true), FastlaneCore::ConfigItem.new(key: :verbose, description: "verbose", optional: true, default_value: false, type: Boolean) ] end |
.description ⇒ Object
54 55 56 |
# File 'lib/fastlane/plugin/json_auth/actions/merge_jsons_action.rb', line 54 def self.description "Merge a group of jsons files and expose a hash with symbolized names as result. Last json predominate over the rest" end |
.details ⇒ Object
58 59 60 |
# File 'lib/fastlane/plugin/json_auth/actions/merge_jsons_action.rb', line 58 def self.details "Use this action to merge jsons files and access to it as Hash with symbolized names. Also you can set the output_path to save the result" end |
.is_supported?(_platform) ⇒ Boolean
99 100 101 |
# File 'lib/fastlane/plugin/json_auth/actions/merge_jsons_action.rb', line 99 def self.is_supported?(_platform) true end |
.print_params(options) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/fastlane/plugin/json_auth/actions/merge_jsons_action.rb', line 84 def self.print_params() table_title = "Params for merge_json #{Fastlane::JsonAuth::VERSION}" FastlaneCore::PrintTable.print_values(config: , hide_keys: [], title: table_title) end |
.put_error!(message) ⇒ Object
49 50 51 52 |
# File 'lib/fastlane/plugin/json_auth/actions/merge_jsons_action.rb', line 49 def self.put_error!() UI.user_error!() raise StandardError, end |
.return_value ⇒ Object
91 92 93 |
# File 'lib/fastlane/plugin/json_auth/actions/merge_jsons_action.rb', line 91 def self.return_value "Hash" end |
.run(params) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fastlane/plugin/json_auth/actions/merge_jsons_action.rb', line 12 def self.run(params) jsons_paths = params[:jsons_paths] output_path = params[:output_path] @is_verbose = params[:verbose] print_params(params) if @is_verbose put_error!("jsons_path cannot be empty.") if jsons_paths.empty? hashes = jsons_paths.map do |json_path| put_error!("json_path: #{json_path} is not valid.") unless File.exist?(json_path) json_content = File.read(File.(json_path)) begin JSON.parse(json_content, symbolize_names: true) rescue StandardError put_error!("File at path #{json_path} has invalid content.") end end merged_hash = hashes.reduce({}, :merge) write_hash_at(output_path, merged_hash) unless output_path.to_s.empty? merged_hash end |
.write_hash_at(output_path, hash) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fastlane/plugin/json_auth/actions/merge_jsons_action.rb', line 37 def self.write_hash_at(output_path, hash) = File.(output_path) file_dir = File.dirname() Dir.mkdir(file_dir) unless File.directory?(file_dir) begin File.write(output_path, JSON.pretty_generate(hash)) rescue StandardError put_error!("Failed to write json at #{output_path}.") end end |