Module: Perpetuity::RailsModel::ActiveModelish

Defined in:
lib/perpetuity/rails_model.rb

Instance Method Summary collapse

Instance Method Details

#humanObject



55
56
57
58
59
60
61
62
# 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_keyObject



64
65
66
# File 'lib/perpetuity/rails_model.rb', line 64

def i18n_key
  name.gsub(/::/, '.').gsub(/([a-z])([A-Z])/, '\1_\2').downcase
end

#model_nameObject



28
29
30
# File 'lib/perpetuity/rails_model.rb', line 28

def model_name
  self
end

#param_keyObject



32
33
34
35
36
37
# 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_keyObject



39
40
41
42
43
44
45
# 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_keyObject



47
48
49
# File 'lib/perpetuity/rails_model.rb', line 47

def singular_route_key
  param_key
end

#to_partial_pathObject



51
52
53
# File 'lib/perpetuity/rails_model.rb', line 51

def to_partial_path
  "#{name.downcase}s/_#{name.downcase}"
end