Class: Danger::PluginJSON

Inherits:
CLAide::Command::Plugins
  • Object
show all
Defined in:
lib/danger/commands/plugins/plugin_json.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ PluginJSON

Returns a new instance of PluginJSON.



11
12
13
14
15
16
# File 'lib/danger/commands/plugins/plugin_json.rb', line 11

def initialize(argv)
  @refs = argv.arguments! unless argv.arguments.empty?
  @cork = Cork::Board.new(silent: argv.option("silent", false),
                          verbose: argv.option("verbose", false))
  super
end

Instance Attribute Details

#corkObject

Returns the value of attribute cork.



9
10
11
# File 'lib/danger/commands/plugins/plugin_json.rb', line 9

def cork
  @cork
end

Instance Method Details

#runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/danger/commands/plugins/plugin_json.rb', line 26

def run
  file_resolver = PluginFileResolver.new(@refs)
  data = file_resolver.resolve

  parser = PluginParser.new(data[:paths])
  parser.parse
  json = parser.to_json

  # Append gem metadata into every plugin
  data[:gems].each do |gem_data|
    json.each do |plugin|
      plugin[:gem_metadata] = gem_data if plugin[:gem] == gem_data[:gem]
    end
  end

  cork.puts json.to_json
end