Class: ADLicenseLint::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/ad_licenselint/runner.rb

Constant Summary collapse

POD_SOURCES =
["trunk", "master"]
.map { |source| File.join(ENV["HOME"], ".cocoapods/repos", source) }
.select { |path| File.exist? path }
.map { |path| Pod::Source.new path }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Runner

Returns a new instance of Runner.



13
14
15
16
17
18
19
20
# File 'lib/ad_licenselint/runner.rb', line 13

def initialize(options = nil)
  if options.nil?
    @options = OptionHandler.parse
  else
    @options = ADLicenseLint::Constant::DEFAULT_OPTIONS.merge(options)
  end
  @path = File.expand_path(@options[:path])
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/ad_licenselint/runner.rb', line 6

def options
  @options
end

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/ad_licenselint/runner.rb', line 6

def path
  @path
end

Instance Method Details

#create_reportObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ad_licenselint/runner.rb', line 22

def create_report
  raise "Folder #{target_support_path} does not exist" if Dir[target_support_path].empty?

  plist_files = Dir[acknowledgements_plist_path] # one plist for each target
  json_contents = plist_files.map { |plist_file| acknowledgement_json(plist_file) }
  entries = all_entries(json_contents)
  warning_entries = entries.reject { |entry| accepted? entry }
  displayed_entries = options[:all] ? entries : warning_entries

  Report.new(displayed_entries)
end

#format(report) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ad_licenselint/runner.rb', line 34

def format(report)
  if report.empty?
    LOGGER.log(:info, :green, "No warnings found.")
    return ""
  end

  case options[:format]
  when ADLicenseLint::Constant::MARKDOWN_FORMAT_OPTION
    MarkdownFormatter.new(report).formatted_content
  when ADLicenseLint::Constant::TERMINAL_FORMAT_OPTION
    TerminalFormatter.new(report).formatted_content
  end
end

#runObject



48
49
50
# File 'lib/ad_licenselint/runner.rb', line 48

def run
  format create_report
end