class Gorillib::Model::Name
Attributes
cache_key[R]
collection[R]
element[R]
i18n_key[R]
namespace[RW]
param_key[R]
partial_path[R]
singular[R]
Public Class Methods
new(klass, namespace = nil, name = nil)
click to toggle source
Calls superclass method
# File lib/gorillib/model/active_model_naming.rb, line 11 def initialize(klass, namespace = nil, name = nil) name ||= klass.name raise ArgumentError, "Class name cannot be blank. You need to supply a name argument when anonymous class given" if name.blank? super(name) @klass = klass @singular = _singularize(self).freeze @element = inflector.underscore(inflector.demodulize(self)).freeze @human = inflector.humanize(@element).freeze @i18n_key = inflector.underscore(self).to_sym # self.namespace = namespace self.plural = inflector.pluralize(@singular) end
Public Instance Methods
namespace=(ns)
click to toggle source
# File lib/gorillib/model/active_model_naming.rb, line 34 def namespace=(ns) if ns.present? @unnamespaced = self.sub(/^#{ns.name}::/, '') @param_key = _singularize(@unnamespaced).freeze else @unnamespaced = nil @param_key = @singular.freeze end end
plural=(str)
click to toggle source
# File lib/gorillib/model/active_model_naming.rb, line 27 def plural=(str) @plural = str.dup.freeze @collection = inflector.underscore(@plural).freeze @partial_path = "#{@collection}/#{@element}".freeze str end
route_key()
click to toggle source
# File lib/gorillib/model/active_model_naming.rb, line 48 def route_key rk = (namespace ? inflector.pluralize(param_key) : plural.dup) rk << "_index" if plural == singular rk.freeze end
singular_route_key()
click to toggle source
# File lib/gorillib/model/active_model_naming.rb, line 44 def singular_route_key inflector.singularize(route_key).freeze end
Private Instance Methods
_singularize(string, replacement='_')
click to toggle source
# File lib/gorillib/model/active_model_naming.rb, line 56 def _singularize(string, replacement='_') inflector.underscore(string).tr('/', replacement) end