Class: Monban::FieldMap

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

Overview

FieldMap is used to allow multiple lookup fields. For instance if you wanted to allow a user to sign in via email or username. This is used internally by the authenticate_session controller helper

Since:

  • 0.0.15

Instance Method Summary collapse

Constructor Details

#initialize(params, field_map) ⇒ FieldMap

Returns a new instance of FieldMap.

Parameters:

  • params (Hash)

    hash of parameters

  • field_map (Hash)

    hash of values to map

Since:

  • 0.0.15



9
10
11
12
# File 'lib/monban/field_map.rb', line 9

def initialize params, field_map
  @params = params
  @field_map = field_map
end

Instance Method Details

#to_fieldsArray, Hash

converts params into values that can be passed into a where clause

Returns:

  • (Array)

    if initialized with field_map

  • (Hash)

    if not initialized with field_map

Since:

  • 0.0.15



18
19
20
21
22
23
24
# File 'lib/monban/field_map.rb', line 18

def to_fields
  if @field_map
    params_from_field_map
  else
    params_with_symbolized_keys
  end
end