Class: Fastlane::Actions::ReadJsonAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



84
85
86
# File 'lib/fastlane/plugin/json_auth/actions/read_json_action.rb', line 84

def self.authors
  ["Martin Gonzalez"]
end

.available_optionsObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fastlane/plugin/json_auth/actions/read_json_action.rb', line 55

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :json_path,
                                 description: "Path to json file",
                                 is_string: true,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :json_string,
                                 description: "A json as string",
                                 is_string: true,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :verbose,
                                 description: "verbose",
                                 optional: true,
                                 type: Boolean)

  ]
end

.descriptionObject



47
48
49
# File 'lib/fastlane/plugin/json_auth/actions/read_json_action.rb', line 47

def self.description
  "Read a json file and expose a hash with symbolized names as result"
end

.detailsObject



51
52
53
# File 'lib/fastlane/plugin/json_auth/actions/read_json_action.rb', line 51

def self.details
  "Use this action to read a json file and access to it as Hash with symbolized names"
end

.is_supported?(_platform) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/fastlane/plugin/json_auth/actions/read_json_action.rb', line 88

def self.is_supported?(_platform)
  true
end


73
74
75
76
77
78
# File 'lib/fastlane/plugin/json_auth/actions/read_json_action.rb', line 73

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

.put_error!(message) ⇒ Object

Raises:

  • (StandardError)


42
43
44
45
# File 'lib/fastlane/plugin/json_auth/actions/read_json_action.rb', line 42

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

.return_valueObject



80
81
82
# File 'lib/fastlane/plugin/json_auth/actions/read_json_action.rb', line 80

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
36
37
38
39
40
# File 'lib/fastlane/plugin/json_auth/actions/read_json_action.rb', line 12

def self.run(params)
  json_path = params[:json_path]
  json_string = params[:json_string]
  @is_verbose = params[:verbose]

  if json_path.nil? && json_string.nil?
    put_error!("You need to provide a json_path (file to path) or json_string (json as string).")
    return nil
  end

  print_params(params) if @is_verbose

  json_content = json_string

  unless json_path.nil?
    unless File.file?(json_path)
      put_error!("File at path #{json_path} does not exist. Verify that the path is correct.")
      return nil
    end

    json_content = File.read(json_path)
  end

  begin
    JSON.parse(json_content, symbolize_names: true)
  rescue StandardError
    put_error!("File at path #{json_path} has invalid content.")
  end
end