# File lib/foreman_maintain/param.rb, line 5 def initialize(name, description, options, &block) options.validate_options!(:description, :required, :flag, :array) @name = name @description = description || options[:description] || '' @options = options @required = @options.fetch(:required, false) @flag = @options.fetch(:flag, false) @block = block @array = @options.fetch(:array, false) end
# File lib/foreman_maintain/param.rb, line 24 def array? @array end
# File lib/foreman_maintain/param.rb, line 16 def flag? @flag end
rubocop:disable Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity
# File lib/foreman_maintain/param.rb, line 29 def process(value) value = process_array(value) if array? value = @block.call(value) if @block if value.nil? && required? raise ArgumentError, "Param #{name} is required but no value given" elsif flag? value = value ? true : false end value end
rubocop:enable Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity
# File lib/foreman_maintain/param.rb, line 41 def process_array(value) if value.is_a?(Array) value else value.to_s.split(',').map(&:strip) end end
# File lib/foreman_maintain/param.rb, line 20 def required? @required end