Project

General

Profile

« Previous | Next » 

Revision a7f78b19

Added by Ohad Levy over 12 years ago

  • ID a7f78b1919e885a0bdc8a3b0109264bb24c93b35

fixes #1148 - CRUD on lookup values via the API

View differences:

app/models/lookup_value.rb
class LookupValue < ActiveRecord::Base
include Authorization
belongs_to :lookup_key
validates_uniqueness_of :match, :scope => :lookup_key_id
validates_presence_of :match, :value
validates_presence_of :match, :value, :lookup_key_id
delegate :key, :to => :lookup_key
validate :validate_range, :validate_list, :validate_regexp, :validate_match
before_validation :sanitize_match
......
default_scope :order => 'LOWER(lookup_values.value)'
scoped_search :on => :value, :complete_value => true, :default_order => true
scoped_search :on => :match, :complete_value => true
scoped_search :in => :lookup_key, :on => :key, :rename => :lookup_key, :complete_value => true
def name
value
end
private
# TODO: ensures that the match contain only allowed path elements
......
return true unless (lookup_key.validator_type == 'list')
errors.add(:value, "not in list") and return false unless lookup_key.validator_rule.split(LookupKey::KEY_DELM).map(&:strip).include?(value)
end
def as_json(options={})
super({:only => [:value, :match, :lookup_key_id, :id]}.merge(options))
end
end

Also available in: Unified diff