Sha256: 5173d03227a42527508cf6f7849152d954a907dd70e6d177da11d9b168ee3d5a

Contents?: true

Size: 651 Bytes

Versions: 4

Compression:

Stored size: 651 Bytes

Contents

module Guts
  # Option model
  class Option < ActiveRecord::Base
    include TrackableConcern
    
    # Regex for replacing key values with
    KEY_REGEX = /[^a-zA-Z0-9_ ]/i
    
    validates :key, presence: true, length: {minimum: 3}
    
    trackable :create, :update, :destroy, fields: [:value]
    
    # Setter override for setting key
    def key=(key)
      self[:key] = key.gsub(KEY_REGEX, "").gsub(/\s+/, "_").downcase.chomp
    end
    
    # Simple helper lookup for keys
    # @param [Symbol] key the option key to look up
    # @return [Object] the option record
    def self.for_key(key)
      self.find_by_key(key)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
guts-1.0.8 app/models/guts/option.rb
guts-1.0.7 app/models/guts/option.rb
guts-1.0.5 app/models/guts/option.rb
guts-1.0.3 app/models/guts/option.rb