Class: RailsPackager::CommandParser

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ CommandParser

Returns a new instance of CommandParser.



9
10
11
12
# File 'lib/rails_packager/command_parser.rb', line 9

def initialize(command)
  @parsed = false
  @unparsed = command
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



3
4
5
# File 'lib/rails_packager/command_parser.rb', line 3

def args
  @args
end

#envObject (readonly)

Returns the value of attribute env.



3
4
5
# File 'lib/rails_packager/command_parser.rb', line 3

def env
  @env
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/rails_packager/command_parser.rb', line 3

def name
  @name
end

Class Method Details

.parse(command) ⇒ Object



5
6
7
# File 'lib/rails_packager/command_parser.rb', line 5

def self.parse(command)
  new(command).tap(&:parse)
end

Instance Method Details

#parseObject

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rails_packager/command_parser.rb', line 14

def parse
  return if @parsed
  @parsed = true

  result =
    if @unparsed.is_a?(Array)
      @env = parse_env(@unparsed.last)
      parse_command(@unparsed.first)
    else
      @env = {}
      parse_command(@unparsed)
    end

  raise ArgumentError, "Empty command is not allowed" if result.empty?
  @name = result.shift
  @args = result
end