Class: RailsAsyncMethods::ParameterParser
- Defined in:
- lib/rails_async_methods/parameter_parser.rb
Constant Summary collapse
- REQ_POS_DELIMETER =
','.freeze
- OPT_POS_DELIMETER =
'=nil,'.freeze
- REST_POS_DELIMETER =
['*', ','].freeze
- REQ_KEY_DELIMETER =
':,'.freeze
- OPT_KEY_DELIMETER =
':nil,'.freeze
- REST_KEY_DELIMETER =
['**', ','].freeze
- BLOCK_DELIMETER =
'&'.freeze
Instance Attribute Summary collapse
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Instance Method Summary collapse
- #arg_values_for_job(&block) ⇒ Object
- #as_argument_string ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(parameters) ⇒ ParameterParser
constructor
A new instance of ParameterParser.
Constructor Details
#initialize(parameters) ⇒ ParameterParser
Returns a new instance of ParameterParser.
12 13 14 |
# File 'lib/rails_async_methods/parameter_parser.rb', line 12 def initialize(parameters) @parameters = parameters end |
Instance Attribute Details
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
10 11 12 |
# File 'lib/rails_async_methods/parameter_parser.rb', line 10 def parameters @parameters end |
Instance Method Details
#arg_values_for_job(&block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rails_async_methods/parameter_parser.rb', line 26 def arg_values_for_job(&block) final_arg_values = [[], {}] @parameters.each do |type, name| case type when :req, :opt final_arg_values[0].append(block.call(name)) when :rest final_arg_values[0].append(*block.call(name)) when :keyreq, :key final_arg_values[1].merge!(name => block.call(name)) when :keyrest final_arg_values[1].merge!(block.call(name)) end end final_arg_values end |
#as_argument_string ⇒ Object
20 21 22 23 24 |
# File 'lib/rails_async_methods/parameter_parser.rb', line 20 def as_argument_string return '' if @parameters.empty? parameters.map { |type, name| to_argument_string(type, name)}.join.chomp(',') end |
#empty? ⇒ Boolean
16 17 18 |
# File 'lib/rails_async_methods/parameter_parser.rb', line 16 def empty? parameters.empty? end |