class Pronto::Labelman

Public Class Methods

new(patches, commit = nil) click to toggle source
Calls superclass method
# File lib/pronto/labelman.rb, line 8
def initialize(patches, commit = nil)
  super

  @rules_load_path = ENV['LABELMAN_RULES']

  if @rules_load_path
    p "Using additional rules load path #{File.absolute_path(@rules_load_path)}"
    require_and_load_rules
  end
end

Public Instance Methods

run() click to toggle source
# File lib/pronto/labelman.rb, line 19
def run
  return [] unless @patches
  rule_classes = get_all_rule_implems
  if rule_classes.empty?
    p "There are no rule implementations found. Additional load path specified: #{@rules_load_path || '<NONE>'}"
    return []
  end

  rule_classes.map do |rule_class|
    p "Applying rule #{rule_class.name}"
    [rule_class.new(@patches).apply]
  end.compact
end

Private Instance Methods

get_all_rule_implems() click to toggle source
# File lib/pronto/labelman.rb, line 47
def get_all_rule_implems
  ns = Pronto::LabelmanRules
  ns.constants.map do |c|
    probable_class = ns.const_get(c)
    if probable_class.is_a?(Class) &&
      probable_class != Pronto::LabelmanRules::Rule
      probable_class
    end
  end.compact
end
is_frontend_file?(patch) click to toggle source
# File lib/pronto/labelman.rb, line 35
def is_frontend_file?(patch)
  File.extname(patch.new_file_full_path) =~ /\.(s*(c|a)ss|j(s|st\.ejs)|coffee)$/
end
require_and_load_rules() click to toggle source
# File lib/pronto/labelman.rb, line 39
def require_and_load_rules
  load_dir = "#{File.absolute_path(@rules_load_path)}/*.rb"
  Dir[load_dir].each do |file|
    require file
    load file
  end
end