Class: Fastlane::Actions::ReadJsonAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



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

def self.authors
  ["Martin Gonzalez"]
end

.available_optionsObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fastlane/plugin/json/actions/read_json_action.rb', line 51

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



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

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

.detailsObject



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

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)


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

def self.is_supported?(_platform)
  true
end


69
70
71
72
73
74
# File 'lib/fastlane/plugin/json/actions/read_json_action.rb', line 69

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

.put_error!(message) ⇒ Object

Raises:

  • (StandardError)


38
39
40
41
# File 'lib/fastlane/plugin/json/actions/read_json_action.rb', line 38

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

.return_valueObject



76
77
78
# File 'lib/fastlane/plugin/json/actions/read_json_action.rb', line 76

def self.return_value
  "Hash"
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
29
30
31
32
33
34
35
36
# File 'lib/fastlane/plugin/json/actions/read_json_action.rb', line 8

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
    put_error!("File at path #{json_path} has invalid content. ❌")
  end
end