rosa-build/lib/ext/rails/reserved_name_validator.rb

39 lines
1.2 KiB
Ruby
Raw Normal View History

class ReservedNameValidator < ActiveModel::EachValidator
RESERVED_NAMES = %w{
2013-05-06 18:50:16 +01:00
about account add admin administrator api autocomplete_group_uname
app apps archive archives auth
blog
config connect contact create commit commits
dashboard delete direct_messages download downloads
edit email
faq favorites feed feeds follow followers following
help home
invitations invite
jobs
login log-in log_in logout log-out log_out logs
map maps
new none
oauth oauth_clients openid
privacy
register remove replies rss root
save search sessions settings
signup sign-up sign_up signin sign-in sign_in signout sign-out sign_out
sitemap ssl subscribe
teams terms test tour trends tree
2013-05-06 18:50:16 +01:00
unfollow unsubscribe upload uploads url user
widget widgets wiki
xfn xmpp
}
def reserved_names
@reserved_names ||= RESERVED_NAMES +
Rails.application.routes.routes.map{|r| r.path.spec.to_s.match(/^\/([\w-]+)/)[1] rescue nil}.uniq.compact # current routes
end
def validate_each(record, attribute, value)
if reserved_names.include?(value.to_s.downcase)
2014-01-21 04:51:49 +00:00
record.errors.add(attribute, :exclusion, options.merge(value: value))
end
end
end