Module: Perpetuity::RailsModel::ActiveModelish
- Defined in:
- lib/perpetuity/rails_model.rb
Instance Method Summary collapse
- #human ⇒ Object
- #i18n_key ⇒ Object
- #model_name ⇒ Object
- #param_key ⇒ Object
- #route_key ⇒ Object
- #singular_route_key ⇒ Object
- #to_partial_path ⇒ Object
Instance Method Details
#human ⇒ Object
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_key ⇒ Object
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_name ⇒ Object
28 29 30 |
# File 'lib/perpetuity/rails_model.rb', line 28 def model_name self end |
#param_key ⇒ Object
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_key ⇒ Object
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_key ⇒ Object
47 48 49 |
# File 'lib/perpetuity/rails_model.rb', line 47 def singular_route_key param_key end |
#to_partial_path ⇒ Object
51 52 53 |
# File 'lib/perpetuity/rails_model.rb', line 51 def to_partial_path "#{name.downcase}s/_#{name.downcase}" end |