Sha256: 65097da0b9305f01d2bb95d34bd26a43d0c2ab2ebdeb587ee0701578a1967e8a

Contents?: true

Size: 579 Bytes

Versions: 8

Compression:

Stored size: 579 Bytes

Contents

module MotherBrain::API::Validators
  # Coerce a URI friendly version string into a SemVer string
  #
  # @example coercing a URI friendly string into a SemVer string
  #
  #   "1_0_0" => "1.0.0"
  class SemVer < Grape::Validations::Validator
    def validate_param!(attr_name, params)
      return nil if params[attr_name].nil?

      ver_string = params[attr_name].gsub('_', '.')
      Solve::Version.split(ver_string)
      params[attr_name] = ver_string
    rescue Solve::Errors::InvalidVersionFormat => ex
      throw :error, status: 400, message: ex.to_s
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
motherbrain-1.1.1 lib/mb/api/validators/sem_ver.rb
motherbrain-1.1.0 lib/mb/api/validators/sem_ver.rb
motherbrain-1.0.0 lib/mb/api/validators/sem_ver.rb
motherbrain-0.14.5 lib/mb/api/validators/sem_ver.rb
motherbrain-0.14.4 lib/mb/api/validators/sem_ver.rb
motherbrain-0.14.3 lib/mb/api/validators/sem_ver.rb
motherbrain-0.14.2 lib/mb/api/validators/sem_ver.rb
motherbrain-0.13.1 lib/mb/api/validators/sem_ver.rb