module Perpetuity::RailsModel::ActiveModelish

Public Instance Methods

human() click to toggle source
# File lib/perpetuity/rails_model.rb, line 55
def human
  if name == name.upcase
    name.split(/_/).map(&:capitalize).join(' ')
  else
    name.gsub(/::|_/, ' ')
        .gsub(/(\w)([A-Z])/, '\1 \2')
  end
end
i18n_key() click to toggle source
# File lib/perpetuity/rails_model.rb, line 64
def i18n_key
  name.gsub(/::/, '.').gsub(/([a-z])([A-Z])/, '\1_\2').downcase
end
model_name() click to toggle source
# File lib/perpetuity/rails_model.rb, line 28
def model_name
  self
end
param_key() click to toggle source
# File lib/perpetuity/rails_model.rb, line 32
def param_key
  to_s.gsub('::', '_')
      .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
      .gsub(/([a-z\d])([A-Z])/,'\1_\2')
      .downcase
end
route_key() click to toggle source
# File lib/perpetuity/rails_model.rb, line 39
def route_key
  if defined? ActiveSupport::Inflector
    ActiveSupport::Inflector.pluralize(param_key)
  else
    param_key + 's'
  end
end
singular_route_key() click to toggle source
# File lib/perpetuity/rails_model.rb, line 47
def singular_route_key
  param_key
end
to_partial_path() click to toggle source
# File lib/perpetuity/rails_model.rb, line 51
def to_partial_path
  "#{name.downcase}s/_#{name.downcase}"
end