Class: Fastlane::Actions::WriteJsonAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/json_auth/actions/write_json_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



79
80
81
# File 'lib/fastlane/plugin/json_auth/actions/write_json_action.rb', line 79

def self.authors
  ["Martin Gonzalez"]
end

.available_optionsObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fastlane/plugin/json_auth/actions/write_json_action.rb', line 45

def self.available_options
  [
    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

.descriptionObject



37
38
39
# File 'lib/fastlane/plugin/json_auth/actions/write_json_action.rb', line 37

def self.description
  "Write a json file from a hash at the provided path"
end

.detailsObject



41
42
43
# File 'lib/fastlane/plugin/json_auth/actions/write_json_action.rb', line 41

def self.details
  "Use this action to serialize a hash into a json file in a provided path."
end

.is_supported?(_platform) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/fastlane/plugin/json_auth/actions/write_json_action.rb', line 83

def self.is_supported?(_platform)
  true
end


68
69
70
71
72
73
# File 'lib/fastlane/plugin/json_auth/actions/write_json_action.rb', line 68

def self.print_params(options)
  table_title = "Params for write_json #{Fastlane::JsonAuth::VERSION}"
  FastlaneCore::PrintTable.print_values(config: options,
                                        hide_keys: [],
                                        title: table_title)
end

.put_error!(message) ⇒ Object

Raises:

  • (StandardError)


32
33
34
35
# File 'lib/fastlane/plugin/json_auth/actions/write_json_action.rb', line 32

def self.put_error!(message)
  UI.user_error!(message)
  raise StandardError, message
end

.return_valueObject



75
76
77
# File 'lib/fastlane/plugin/json_auth/actions/write_json_action.rb', line 75

def self.return_value
  "Nothing"
end

.run(params) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fastlane/plugin/json_auth/actions/write_json_action.rb', line 12

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_path_expanded = File.expand_path(file_path)
  file_dir = File.dirname(file_path_expanded)
  Dir.mkdir(file_dir) unless File.directory?(file_dir)

  begin
    File.write(file_path, JSON.pretty_generate(hash))
  rescue StandardError
    put_error!("File at path #{file_path} has invalid content.")
  end
end