Module: Spree::MaintenanceTasks::ArgumentParser
- Defined in:
- app/services/spree/maintenance_tasks/argument_parser.rb
Overview
Turns the CLI's ARGS='market_id=mkt_1 batch_size=200' into the hash the
task's ActiveModel attributes expect.
Values stay strings: attribute types cast them, so the parser never has
to guess whether 200 is a number or a label.
Constant Summary collapse
- TOKEN =
Quoted values may contain spaces: ARGS='label="two words" limit=5'.
/(\w+)=("[^"]*"|'[^']*'|\S+)/
Class Method Summary collapse
Class Method Details
.parse(raw) ⇒ Hash{String => String}
14 15 16 17 18 19 20 |
# File 'app/services/spree/maintenance_tasks/argument_parser.rb', line 14 def self.parse(raw) return {} if raw.blank? raw.scan(TOKEN).to_h do |key, value| [key, value.gsub(/\A["']|["']\z/, '')] end end |