Sha256: c5d1ade5222c3ad8f893c6ee5b17a87a4677b083bb0a44d4f2aac5dd6ac9cb26

Contents?: true

Size: 865 Bytes

Versions: 34

Compression:

Stored size: 865 Bytes

Contents

class Marty::Config < Marty::Base
  class ConfigValidator < ActiveModel::Validator
    def validate(entry)
      v = entry.get_value
      entry.errors[:base] << 'bad JSON value' if v.nil?
      v
    end
  end

  validates_presence_of :key, :value
  validates_uniqueness_of :key
  validates_with ConfigValidator

  delorean_fn :lookup, sig: 1 do |key|
    self[key]
  end

  def get_value
    value[0]
  end

  def set_value(v)
    self.value = [v]
  end

  def self.[]=(key, value)
    entry = find_by_key(key)
    if !entry
      entry = new
      entry.key = key
    end
    entry.set_value(value)
    entry.save!

    value
  end

  def self.[](key)
    entry = find_by_key(key)
    entry and entry.get_value
  end

  def self.del(key)
    entry = find_by_key(key)
    if entry
      result = entry.get_value
      entry.destroy
      result
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
marty-6.1.0 app/models/marty/config.rb
marty-5.2.0 app/models/marty/config.rb
marty-5.1.4 app/models/marty/config.rb
marty-5.1.3 app/models/marty/config.rb
marty-5.1.2 app/models/marty/config.rb
marty-5.1.1 app/models/marty/config.rb
marty-5.1.0 app/models/marty/config.rb
marty-3.1.0 app/models/marty/config.rb
marty-3.0.1 app/models/marty/config.rb
marty-4.0.0.rc2 app/models/marty/config.rb
marty-3.0.0 app/models/marty/config.rb
marty-2.9.3 app/models/marty/config.rb
marty-2.9.2 app/models/marty/config.rb
marty-2.9.1 app/models/marty/config.rb
marty-2.8.0 app/models/marty/config.rb
marty-2.7.3 app/models/marty/config.rb
marty-2.7.2 app/models/marty/config.rb
marty-2.7.1 app/models/marty/config.rb
marty-2.7.0 app/models/marty/config.rb
marty-2.6.8 app/models/marty/config.rb