class Rbfmt::CLI

Attributes

args[R]

Public Class Methods

new(args) click to toggle source
# File lib/rbfmt/cli.rb, line 7
def initialize(args)
  @args = args
end
start() click to toggle source
# File lib/rbfmt/cli.rb, line 28
def self.start
  new(ARGV).start
end

Public Instance Methods

start() click to toggle source
# File lib/rbfmt/cli.rb, line 11
def start
  dir = if args.empty?
          File.join("**", "*.rb")
        else
          File.join(args.first, "**", "*.rb")
        end

  Dir[dir].each do |file|
    source = File.read(file)
    formatted_source = Rbfmt::Formatter.new(source).format
    unless source == formatted_source
      File.write(file, formatted_source)
      puts file
    end
  end
end