Class: Guts::Option

Inherits:
ApplicationRecord show all
Includes:
MultisiteScopeConcern
Defined in:
app/models/guts/option.rb

Overview

Option model

Constant Summary collapse

KEY_REGEX =

Regex for replacing key values with

/[^a-zA-Z0-9_ ]/i

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for_key(key) ⇒ Object

Simple helper lookup for keys

Parameters:

  • key (Symbol)

    the option key to look up

Returns:

  • (Object)

    the option record



23
24
25
# File 'app/models/guts/option.rb', line 23

def self.for_key(key)
  find_by key: key
end

Instance Method Details

#key=(key) ⇒ String

Setter override for setting key

Parameters:

  • key (String)

    the option key

Returns:

  • (String)

    cleaned/formatted key



16
17
18
# File 'app/models/guts/option.rb', line 16

def key=(key)
  self[:key] = key.gsub(KEY_REGEX, '').gsub(/\s+/, '_').downcase.chomp
end