Sha256: dc006d445bdab96ebb8d5caf633e68b5d0d294b8903075525f67c94e8beb0d4e

Contents?: true

Size: 874 Bytes

Versions: 52

Compression:

Stored size: 874 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
      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
    self.value[0]
  end

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

  def self.[]=(key, value)
    entry = find_by_key(key)
    if !entry
      entry = self.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

52 entries across 52 versions & 1 rubygems

Version Path
marty-1.0.37 app/models/marty/config.rb
marty-1.0.36 app/models/marty/config.rb
marty-1.0.35 app/models/marty/config.rb
marty-1.0.34 app/models/marty/config.rb
marty-1.0.33 app/models/marty/config.rb
marty-1.0.32 app/models/marty/config.rb
marty-1.0.31 app/models/marty/config.rb
marty-1.0.30 app/models/marty/config.rb
marty-1.0.29 app/models/marty/config.rb
marty-1.0.28 app/models/marty/config.rb
marty-1.0.27 app/models/marty/config.rb
marty-1.0.26 app/models/marty/config.rb
marty-1.0.25 app/models/marty/config.rb
marty-1.0.24 app/models/marty/config.rb
marty-1.0.23 app/models/marty/config.rb
marty-1.0.22 app/models/marty/config.rb
marty-1.0.20 app/models/marty/config.rb
marty-1.0.19 app/models/marty/config.rb
marty-1.0.18 app/models/marty/config.rb
marty-1.0.17 app/models/marty/config.rb