Class: Language

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/sequel/localize/language.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](code) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/sequel/localize/language.rb', line 18

def [](code)
  if code.respond_to? :to_sym
    code = code.to_sym
    (@cache ||= {})[code] ||= super(:code => code.to_s) || create(:code => code, :name => code)
  else
    super
  end
end

Instance Method Details

#after_createObject



11
12
13
14
15
# File 'lib/sequel/localize/language.rb', line 11

def after_create
  Sequel::Plugins::Localize.localized_models.each do |m|
    m.add_translation_accessors code
  end
end

#validateObject



3
4
5
6
7
8
9
# File 'lib/sequel/localize/language.rb', line 3

def validate
  super
  validates_presence [:code, :name]
  validates_unique :code
  # locale string like 'en'
  validates_format /^[a-z]{2}$/, :code
end