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.

Since:

  • 0.0.3



40
41
42
43
# File 'lib/params.rb', line 40

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



28
29
30
# File 'lib/params.rb', line 28

def options
  @options
end

Instance Method Details

#namespaceNilClass, String

The namespace used if any

Returns:

  • (NilClass, String)

Since:

  • 0.0.3



49
50
51
# File 'lib/params.rb', line 49

def namespace
  @options[:space_name]
end

#to_hashHash

Converts the rule into a hash with its name and options.

Returns:

  • (Hash)

Since:

  • 0.0.3



56
57
58
# File 'lib/params.rb', line 56

def to_hash
  {:name => name, :options => options}
end