diff --git a/lib/couchrest.rb b/lib/couchrest.rb index e4a8215..958db9e 100644 --- a/lib/couchrest.rb +++ b/lib/couchrest.rb @@ -69,6 +69,18 @@ module CouchRest Object.module_eval("::#{$1}", __FILE__, __LINE__) end + # extracted from Extlib + # + # Capitalizes the first word and turns underscores into spaces and strips _id. + # Like titleize, this is meant for creating pretty output. + # + # @example + # "employee_salary" #=> "Employee salary" + # "author_id" #=> "Author" + def humanize(lower_case_and_underscored_word) + lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize + end + # todo, make this parse the url and instantiate a Server or Database instance # depending on the specificity. def new(*opts) diff --git a/lib/couchrest/validation/validation_errors.rb b/lib/couchrest/validation/validation_errors.rb index 0852244..b5aa106 100644 --- a/lib/couchrest/validation/validation_errors.rb +++ b/lib/couchrest/validation/validation_errors.rb @@ -60,7 +60,7 @@ module CouchRest cattr_writer :default_error_messages def self.default_error_message(key, field, *values) - field = Extlib::Inflection.humanize(field) + field = CouchRest.humanize(field) @@default_error_messages[key] % [field, *values].flatten end diff --git a/lib/couchrest/validation/validators/format_validator.rb b/lib/couchrest/validation/validators/format_validator.rb index 192f715..eaeb1e1 100644 --- a/lib/couchrest/validation/validators/format_validator.rb +++ b/lib/couchrest/validation/validators/format_validator.rb @@ -64,7 +64,7 @@ module CouchRest error_message = @options[:message] || ValidationErrors.default_error_message(:invalid, field_name) - field = Extlib::Inflection.humanize(field_name) + field = CouchRest.humanize(field_name) error_message = error_message.call(field, value) if error_message.respond_to?(:call) add_error(target, error_message, field_name) diff --git a/lib/couchrest/validation/validators/length_validator.rb b/lib/couchrest/validation/validators/length_validator.rb index 104d5af..272b479 100644 --- a/lib/couchrest/validation/validators/length_validator.rb +++ b/lib/couchrest/validation/validators/length_validator.rb @@ -54,7 +54,7 @@ module CouchRest # XXX: HACK seems hacky to do this on every validation, probably should # do this elsewhere? - field = Extlib::Inflection.humanize(field_name) + field = CouchRest.humanize(field_name) min = @range ? @range.min : @min max = @range ? @range.max : @max equal = @equal