Class: MultiModelWizard::Config

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

Constant Summary collapse

FORM_KEY =

The form key is what is used a the key in the session cookies This can be changed in the intitializer file. This key is also what is used as part of the redis key value pair if redis is configured.

'multi_model_wizard_form'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



11
12
13
14
# File 'lib/multi_model_wizard/config.rb', line 11

def initialize
  @store = { location: :cookies, redis_instance: nil }
  @form_key = FORM_KEY
end

Instance Attribute Details

#form_keyObject

Returns the value of attribute form_key.



9
10
11
# File 'lib/multi_model_wizard/config.rb', line 9

def form_key
  @form_key
end

#storeObject

Returns the value of attribute store.



9
10
11
# File 'lib/multi_model_wizard/config.rb', line 9

def store
  @store
end

Instance Method Details

#locationObject

Location tells the gem where to put your form data between form steps The default is session cookies in the browser



32
33
34
# File 'lib/multi_model_wizard/config.rb', line 32

def location
  store[:location]
end

#redis_instanceObject

The configured redis instance. This is should be set in the initializer. A redis instance is only needed if you are going to use redis to store. Redis is great to use when you have a bigger/longer wizard form. Session cookies max size is 4k, so if the size is over that, consider switching to redis store

Session cookies are still used even when using redis as the store location A key and a uuid is stored on the browser session cookie That uuid is used as the key in redis to retrieve the form data to the controller



26
27
28
# File 'lib/multi_model_wizard/config.rb', line 26

def redis_instance
  store[:redis_instance]
end

#store_in_cookies?Boolean

Logical methods to determine where the gem should store form data

Returns:

  • (Boolean)


42
43
44
# File 'lib/multi_model_wizard/config.rb', line 42

def store_in_cookies?
  store[:location] =! :redis
end

#store_in_redis?Boolean

Logical methods to determine where the gem should store form data

Returns:

  • (Boolean)


37
38
39
# File 'lib/multi_model_wizard/config.rb', line 37

def store_in_redis?
  store[:location] == :redis
end