Class: RailsPackager::CommandParser
- Inherits:
-
Object
- Object
- RailsPackager::CommandParser
- Defined in:
- lib/rails_packager/command_parser.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(command) ⇒ CommandParser
constructor
A new instance of CommandParser.
- #parse ⇒ Object
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
#args ⇒ Object (readonly)
Returns the value of attribute args.
3 4 5 |
# File 'lib/rails_packager/command_parser.rb', line 3 def args @args end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
3 4 5 |
# File 'lib/rails_packager/command_parser.rb', line 3 def env @env end |
#name ⇒ Object (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
#parse ⇒ Object
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 |