class Enforce::CommandLine

Public Instance Methods

execute(argv=[]) click to toggle source
# File lib/enforce/command_line.rb, line 7
def execute(argv=[])
  return show_usage if argv.empty?

  file = find_file argv[0]
  return show_file_not_found unless file

  handler.execute file
  handler.failed? ? 1 : 0
end

Private Instance Methods

find_file(basename) click to toggle source
# File lib/enforce/command_line.rb, line 19
def find_file(basename)
  candidates = [
    "#{basename}.rb",
    "#{home_dir}/#{basename}.rb"
  ]

  candidates.each do |candidate|
    return candidate if File.exist? candidate
  end

  false
end
handler() click to toggle source
# File lib/enforce/command_line.rb, line 32
def handler
  @handler ||= Enforce::Handler.new
end
home_dir() click to toggle source
# File lib/enforce/command_line.rb, line 47
def home_dir
  ENV['ENFORCE_HOME'] ||= "#{Dir.home}/enforce"
end
show_file_not_found() click to toggle source
# File lib/enforce/command_line.rb, line 42
def show_file_not_found
  puts "Error: Could not find rules file"
  1
end
show_usage() click to toggle source
# File lib/enforce/command_line.rb, line 36
def show_usage
  puts "Enforce #{Enforce::VERSION}"
  puts "  Usage: enforce RULES_FILE"
  0
end