Class: Sass::Exec::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sassmagic/reset.rb

Overview

The abstract base class for Sass executables.

Direct Known Subclasses

SassConvert, SassScss

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Base

Returns a new instance of Base.

Parameters:

  • args (Array<String>)

    The command-line arguments



711
712
713
714
# File 'lib/sassmagic/reset.rb', line 711

def initialize(args)
  @args = args
  @options = {}
end

Instance Method Details

#parseObject

Parses the command-line arguments and runs the executable. This does not handle exceptions or exit the program.

See Also:



752
753
754
755
756
757
758
759
760
# File 'lib/sassmagic/reset.rb', line 752

def parse
  @opts = OptionParser.new(&method(:set_opts))

  @opts.parse!(@args)

  process_result

  @options
end

#parse!Object

Parses the command-line arguments and runs the executable. Calls ‘Kernel#exit` at the end, so it never returns.

See Also:



720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
# File 'lib/sassmagic/reset.rb', line 720

def parse!
  # rubocop:disable RescueException
  begin
    parse
  rescue Exception => e
    # Exit code 65 indicates invalid data per
    # http://www.freebsd.org/cgi/man.cgi?query=sysexits. Setting it via
    # at_exit is a bit of a hack, but it allows us to rethrow when --trace
    # is active and get both the built-in exception formatting and the
    # correct exit code.
    at_exit {exit 65} if e.is_a?(Sass::SyntaxError)

    raise e if @options[:trace] || e.is_a?(SystemExit)

    if e.is_a?(Sass::SyntaxError)
      $stderr.puts e.sass_backtrace_str("standard input")
    else
      $stderr.print "#{e.class}: " unless e.class == RuntimeError
      $stderr.puts e.message.to_s
    end
    $stderr.puts "  Use --trace for backtrace."

    exit 1
  end
  exit 0
  # rubocop:enable RescueException
end

#to_sString

Returns A description of the executable.

Returns:

  • (String)

    A description of the executable



763
764
765
# File 'lib/sassmagic/reset.rb', line 763

def to_s
  @opts.to_s
end