Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Ohm monkey patch and include Padrino::Ohm::Validator #1196

Merged
merged 8 commits into from Apr 9, 2013
Expand Up @@ -46,6 +46,14 @@ class Account < Ohm::Model
self[id]
end

##
# This method is used by Admin Sessions Controller for login bypass
#
def self.first
first_id = key[:all].sort(:order => "asc", :limit => [0,1]).first
self[first_id] if first_id
end

def has_password?(password)
::BCrypt::Password.new(crypted_password) == password
end
Expand Down
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/cs.yml
Expand Up @@ -24,3 +24,14 @@ cs:
record_invalid: "Následující pole obsahují chybně vyplněné údaje: %{errors}"
content_type: "nepodporovaný formát souboru"
#activerecord: *activemodel
ohm:
errors:
messages:
format: "není platná hodnota"
not_present: "je povinná položka"
not_numeric: "není číslo"
not_url: "není platná hodnota"
not_email: "není platná hodnota"
not_valid: "není v seznamu povolených hodnot"
not_in_range: "není v seznamu povolených hodnot"
not_decimal: "není platná hodnota"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/da.yml
Expand Up @@ -24,3 +24,14 @@ da:
record_invalid: "Valideringsfejl: %{errors}"
content_type: "fileformatet er ikke understøttet"
activerecord: *activemodel
ohm:
errors:
messages:
format: "er ikke gyldig"
not_present: "må ikke være blank"
not_numeric: "er ikke et tal"
not_url: "er ikke gyldig"
not_email: "er ikke gyldig"
not_valid: "findes ikke i listen"
not_in_range: "findes ikke i listen"
not_decimal: "er ikke gyldig"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/de.yml
Expand Up @@ -24,3 +24,14 @@ de:
record_invalid: "Validierung schlug fehl: %{errors}"
content_type: "Datei-Format wird nicht unterstützt"
activerecord: *activemodel
ohm:
errors:
messages:
format: "ist ungültig"
not_present: "Darf nicht nur Leerzeichen enthalten"
not_numeric: "ist keine Nummer"
not_url: "ist ungültig"
not_email: "ist ungültig"
not_valid: "ist nicht in der Liste enthalten"
not_in_range: "ist nicht in der Liste enthalten"
not_decimal: "ist ungültig"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/en.yml
Expand Up @@ -24,3 +24,14 @@ en:
record_invalid: "Validation failed: %{errors}"
content_type: "file format not supported"
activerecord: *activemodel
ohm:
errors:
messages:
format: "is invalid"
not_present: "can't be blank"
not_numeric: "is not a number"
not_url: "is invalid"
not_email: "is invalid"
not_valid: "is not included in the list"
not_in_range: "is not included in the list"
not_decimal: "is invalid"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/es.yml
Expand Up @@ -24,3 +24,14 @@ es:
record_invalid: "Fallo la validación: %{errors}"
content_type: "formato de archivo no soportado"
activerecord: *activemodel
ohm:
errors:
messages:
format: "es inválido"
not_present: "no puede estar en blanco"
not_numeric: "no es un número"
not_url: "es inválido"
not_email: "es inválido"
not_valid: "no está incluido en la lista"
not_in_range: "no está incluido en la lista"
not_decimal: "es inválido"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/fr.yml
Expand Up @@ -24,3 +24,14 @@ fr:
record_invalid: "La validation a échoué: %{errors}"
content_type: "format de fichier non pris en charge"
activerecord: *activemodel
ohm:
errors:
messages:
format: "est invalide"
not_present: "ne peut pas être vide"
not_numeric: "n'est pas un nombre"
not_url: "est invalide"
not_email: "est invalide"
not_valid: "n'est pas inclus dans la liste"
not_in_range: "n'est pas inclus dans la liste"
not_decimal: "est invalide"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/hu.yml
Expand Up @@ -24,3 +24,14 @@ hu:
record_invalid: "Érvénytelen: %{errors}"
content_type: ": a fájl formátuma nem támogatott"
activerecord: *activemodel
ohm:
errors:
messages:
format: ": érvénytelen"
not_present: ": nem lehet üres"
not_numeric: ": nem szám"
not_url: ": érvénytelen"
not_email: ": érvénytelen"
not_valid: ": a lista nem tartalmazza"
not_in_range: ": a lista nem tartalmazza"
not_decimal: ": érvénytelen"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/it.yml
Expand Up @@ -24,3 +24,14 @@ it:
record_invalid: "Validazione fallita: %{errors}"
content_type: "il seguente tipo di file non è supportato"
activerecord: *activemodel
ohm:
errors:
messages:
format: "non è valido"
not_present: "non può essere lasciato in bianco"
not_numeric: "non è un numero"
not_url: "non è valido"
not_email: "non è valido"
not_valid: "non è incluso nella lista"
not_in_range: "non è incluso nella lista"
not_decimal: "non è valido"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/ja.yml
Expand Up @@ -24,3 +24,14 @@ ja:
record_invalid: "不正なレコードです: %{errors}"
content_type: "そのファイルフォーマットはサポートされていません。"
activerecord: *activemodel
ohm:
errors:
messages:
format: "は、不正な値です"
not_present: "は、空欄であってはなりません"
not_numeric: "は、数字である必要があります"
not_url: "は、不正な値です"
not_email: "は、不正な値です"
not_valid: "は、次の値のうちどれかでなければなりません:"
not_in_range: "は、次の値のうちどれかでなければなりません:"
not_decimal: "は、不正な値です"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/lv.yml
Expand Up @@ -24,3 +24,14 @@ lv:
record_invalid: "Pārbaude neizdevās: %{errors}"
content_type: "faila formāts netiek atblastīts"
activerecord: *activemodel
ohm:
errors:
messages:
format: "nav derīgs"
not_present: "ir jābūt aizpildītam"
not_numeric: "nav skaitlis"
not_url: "nav derīgs"
not_email: "nav derīgs"
not_valid: "nav iekļauts sarakstā"
not_in_range: "nav iekļauts sarakstā"
not_decimal: "nav derīgs"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/nl.yml
Expand Up @@ -24,3 +24,14 @@ nl:
record_invalid: "Validatie mislukt: %{errors}"
content_type: "bestandsformaat niet ondersteund"
activerecord: *activemodel
ohm:
errors:
messages:
format: "is ongeldig"
not_present: "moet opgegeven zijn"
not_numeric: "is geen getal"
not_url: "is ongeldig"
not_email: "is ongeldig"
not_valid: "is niet in de lijst opgenomen"
not_in_range: "is niet in de lijst opgenomen"
not_decimal: "is ongeldig"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/no.yml
Expand Up @@ -24,3 +24,14 @@
record_invalid: "Valideringsfeil: %{errors}"
content_type: "fileformatet er ikke støttet"
activerecord: *activemodel
ohm:
errors:
messages:
format: "er ikke gyldig"
not_present: "kan ikke være blank"
not_numeric: "er ikke et tall"
not_url: "er ikke gyldig"
not_email: "er ikke gyldig"
not_valid: "finnes ikke i listen"
not_in_range: "finnes ikke i listen"
not_decimal: "er ikke gyldig"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/pl.yml
Expand Up @@ -25,3 +25,14 @@ pl:
record_invalid: "Negatywne sprawdzenie poprawności: %{errors}"
content_type: "nieodozwolony format pliku"
activerecord: *activemodel
ohm:
errors:
messages:
format: "jest nieprawidłowe"
not_present: "nie może być puste"
not_numeric: "nie jest liczbą"
not_url: "jest nieprawidłowe"
not_email: "jest nieprawidłowe"
not_valid: "nie znajduje się na liście dopuszczalnych wartości"
not_in_range: "nie znajduje się na liście dopuszczalnych wartości"
not_decimal: "jest nieprawidłowe"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/pt_br.yml
Expand Up @@ -24,3 +24,14 @@ pt_br:
record_invalid: "Falha na validação: %{errors}"
content_type: "o seguinte tipo de arquivo não é suportado"
activerecord: *activemodel
ohm:
errors:
messages:
format: "não é válido"
not_present: "não pode ser deixado em branco"
not_numeric: "não é um número"
not_url: "não é válido"
not_email: "não é válido"
not_valid: "não está incluído na lista"
not_in_range: "não está incluído na lista"
not_decimal: "não é válido"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/ro.yml
Expand Up @@ -24,3 +24,14 @@ ro:
record_invalid: "Eroare la validare: %{errors}"
content_type: "format de fișier neacceptat"
activerecord: *activemodel
ohm:
errors:
messages:
format: "nu este valid"
not_present: "nu poate fi gol"
not_numeric: "nu este un număr"
not_url: "nu este valid"
not_email: "nu este valid"
not_valid: "nu este inclus în listă"
not_in_range: "nu este inclus în listă"
not_decimal: "nu este valid"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/ru.yml
Expand Up @@ -24,3 +24,14 @@ ru:
record_invalid: "Проверка не удалась: %{errors}"
content_type: "формат файла не поддерживается"
activerecord: *activemodel
ohm:
errors:
messages:
format: "неправильный"
not_present: "не может быть пустым"
not_numeric: "не число"
not_url: "неправильный"
not_email: "неправильный"
not_valid: "не входит в список"
not_in_range: "не входит в список"
not_decimal: "неправильный"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/sv.yml
Expand Up @@ -24,3 +24,14 @@ sv:
record_invalid: "Validering misslyckades: %{errors}"
content_type: "filformatet stöds ej"
activerecord: *activemodel
ohm:
errors:
messages:
format: "är ogiltig"
not_present: "kan inte vara blankt"
not_numeric: "är inte ett tal"
not_url: "är ogiltig"
not_email: "är ogiltig"
not_valid: "är inte inkluderad i listan"
not_in_range: "är inte inkluderad i listan"
not_decimal: "är ogiltig"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/tr.yml
Expand Up @@ -24,3 +24,14 @@ tr:
record_invalid: "Doğrulama gerçekleşmedi: %{errors}"
content_type: "Dosya biçimi desteklenmiyor"
activerecord: *activemodel
ohm:
errors:
messages:
format: "geçerli değil"
not_present: "boş bırakılamaz"
not_numeric: "sayı değil"
not_url: "geçerli değil"
not_email: "geçerli değil"
not_valid: "listede yok"
not_in_range: "listede yok"
not_decimal: "geçerli değil"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/uk.yml
Expand Up @@ -24,3 +24,14 @@ uk:
record_invalid: "Перевірка не вдалася: %{errors}"
content_type: "формат файлу не підтримується"
activerecord: *activemodel
ohm:
errors:
messages:
format: "недійсний"
not_present: "не може бути порожнім"
not_numeric: "не число"
not_url: "недійсний"
not_email: "недійсний"
not_valid: "не входить у список"
not_in_range: "не входить у список"
not_decimal: "недійсний"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/zh_cn.yml
Expand Up @@ -24,3 +24,14 @@ zh_cn:
record_invalid: "校验失败: %{errors}"
content_type: "档案格式不支援"
activerecord: *activemodel
ohm:
errors:
messages:
format: "是无效的"
not_present: "不能是空白字元"
not_numeric: "不是数字"
not_url: "是无效的"
not_email: "是无效的"
not_valid: "没有包含在列表中"
not_in_range: "没有包含在列表中"
not_decimal: "是无效的"
11 changes: 11 additions & 0 deletions padrino-admin/lib/padrino-admin/locale/orm/zh_tw.yml
Expand Up @@ -24,3 +24,14 @@ zh_tw:
record_invalid: "校驗失敗: %{errors}"
content_type: "檔案格式不支援"
activerecord: *activemodel
ohm:
errors:
messages:
format: "是無效的"
not_present: "不能是空白字元"
not_numeric: "不是數字"
not_url: "是無效的"
not_email: "是無效的"
not_valid: "沒有包含在列表中"
not_in_range: "沒有包含在列表中"
not_decimal: "是無效的"
55 changes: 1 addition & 54 deletions padrino-gen/lib/padrino-gen/generators/components/orms/ohm.rb
Expand Up @@ -20,63 +20,10 @@
# when :production then Ohm.connect(:db => 1)
# when :test then Ohm.connect(:db => 2)
# end

# This monkey patch provides traditional (hash of arrays) error handling for ohm models
# Also add compatiblity with admin generator.
module Ohm
class Model

alias_method :old_errors, :errors
def errors
@errors ||= ErrorsHash.new(self.class.to_reference, self.old_errors)
end

def update_attributes(attrs)
attrs.each do |key, value|
send(:"\#{key}=", value)
end if attrs
end

class << self
alias_method :old_attribute, :attribute
def attribute(name, cast=nil)
attributes << name
old_attribute(name, cast)
end

def attributes
@_attributes ||= []
end
end

class ErrorsHash < Hash
def initialize(scope, errors)
@scope = scope
self.replace Hash.new { |hash, key| hash[key] = [] }

errors.each do |key, value|
self[key] << value
end
end

def push(arr)
self[arr[0]] << arr[1]
end

def full_messages
self.map do |key, value|
value.uniq.map do |reason|
I18n::t("ohm.%s.%s.%s" % [@scope, key, reason])
end.join(', ')
end
end
end
end
end # unless Ohm::Model.new.errors.is_a?(Hash)
OHM

def setup_orm
require_dependencies 'ohm'
require_dependencies 'ohm', :version => "~> 1.3.0"
create_file("config/database.rb", OHM)
end

Expand Down