Class: WSDSL::Params::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/params.rb

Overview

Params usually have a few rules used to validate requests. Rules are not usually initialized directly but instead via the service’s #params accessor.

Since:

  • 0.0.3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts = {}) ⇒ Rule

Returns a new instance of Rule.

Parameters:

  • name (Symbol, String)

    The param’s name

  • opts (Hash) (defaults to: {})

    The rule options

Options Hash (opts):

  • :in (Symbol)

    A list of acceptable values.

  • :options (Symbol)

    A list of acceptable values.

  • :default (Symbol)

    The default value of the param.

  • :minvalue (Symbol)

    The minimum acceptable value.

  • :maxvalue (Symbol)

    The maximim acceptable value.

  • :minlength (Symbol)

    The minimum acceptable string length.

  • :maxlength (Symbol)

    The maximum acceptable string length.

Since:

  • 0.0.3



44
45
46
47
# File 'lib/params.rb', line 44

def initialize(name, opts = {})
  @name    = name
  @options = opts
end

Instance Attribute Details

#nameSymbol, String (readonly)

Returns name The name of the param the rule applies to.

Returns:

  • (Symbol, String)

    name The name of the param the rule applies to.

Since:

  • 0.0.3



19
20
21
# File 'lib/params.rb', line 19

def name
  @name
end

#optionsHash (readonly)

Returns options The rule options.

Returns:

  • (Hash)

    options The rule options.

Since:

  • 0.0.3



30
31
32
# File 'lib/params.rb', line 30

def options
  @options
end

Instance Method Details

#namespaceNilClass, String

The namespace used if any

Returns:

  • (NilClass, String)

Since:

  • 0.0.3



53
54
55
# File 'lib/params.rb', line 53

def namespace
  @options[:space_name]
end