Sha256: cce2254e5ffbf273b9d5fdb9a6ac704a672f0f1b6fc84b4648ef37ba09ea55d3

Contents?: true

Size: 741 Bytes

Versions: 12

Compression:

Stored size: 741 Bytes

Contents

module Guts
  # Option model
  class Option < ActiveRecord::Base
    include TrackableConcern
    include MultisiteScopeConcern
    
    # Regex for replacing key values with
    KEY_REGEX = /[^a-zA-Z0-9_ ]/i
    
    validates :key, presence: true, length: { minimum: 3 }
    
    belongs_to :site
    has_many :tracks, as: :object
    
    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)
      find_by_key key
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
guts-1.3.6 app/models/guts/option.rb
guts-1.3.5 app/models/guts/option.rb
guts-1.3.4 app/models/guts/option.rb
guts-1.3.3 app/models/guts/option.rb
guts-1.3.2 app/models/guts/option.rb
guts-1.3.1 app/models/guts/option.rb
guts-1.3.0 app/models/guts/option.rb
guts-1.2.2 app/models/guts/option.rb
guts-1.2.1 app/models/guts/option.rb
guts-1.2.0 app/models/guts/option.rb
guts-1.1.1 app/models/guts/option.rb
guts-1.1.0 app/models/guts/option.rb