Class: RequireJS::Exec::Genetic

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

Direct Known Subclasses

Render

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Genetic

Returns a new instance of Genetic.



22
23
24
25
# File 'lib/requirejs.rb', line 22

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

Instance Method Details

#open_file(filename, flag = 'r') ⇒ Object



66
67
68
69
70
# File 'lib/requirejs.rb', line 66

def open_file(filename, flag = 'r')
  return if filename.nil?
  flag = 'wb' if @options[:unix_newlines] && flag == 'w'
  File.open(filename, flag)
end

#parseObject



44
45
46
47
48
49
50
51
# File 'lib/requirejs.rb', line 44

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:



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/requirejs.rb', line 31

def parse!
  begin
    parse
    rescue Exception => e
      raise e if @options[:trace] || e.is_a?(SystemExit)

      $stderr.print "#{e.class}: " unless e.class == RuntimeError
      $stderr.puts "#{e.message}"
     exit 1
  end
  exit 0
end

#process_resultObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/requirejs.rb', line 53

def process_result
  input, output = @options[:input], @options[:output]
  args = @args.dup
  input ||=
    begin
      filename = args.shift
      @options[:filename] = filename || $stdin
      # open_file(args.shift, 'w') || $stdin
    end
  output ||=open_file(args.shift, 'w') || $stdout
  @options[:input], @options[:output] = input, output
end