Class: Gorillib::Model::Name
- Defined in:
- lib/gorillib/model/active_model_naming.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
(also: #cache_key)
readonly
Returns the value of attribute collection.
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#i18n_key ⇒ Object
readonly
Returns the value of attribute i18n_key.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#param_key ⇒ Object
readonly
Returns the value of attribute param_key.
-
#partial_path ⇒ Object
readonly
Returns the value of attribute partial_path.
-
#singular ⇒ Object
readonly
Returns the value of attribute singular.
Instance Method Summary collapse
-
#initialize(klass, namespace = nil, name = nil) ⇒ Name
constructor
A new instance of Name.
- #plural=(str) ⇒ Object
- #route_key ⇒ Object
- #singular_route_key ⇒ Object
Methods inherited from String
#blank?, #camelize, #constantize, #demodulize, #humanize, #safe_constantize, #snakeize, #titleize, #truncate, #underscore
Constructor Details
#initialize(klass, namespace = nil, name = nil) ⇒ Name
Returns a new instance of Name.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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 |
Instance Attribute Details
#collection ⇒ Object (readonly) Also known as: cache_key
Returns the value of attribute collection
4 5 6 |
# File 'lib/gorillib/model/active_model_naming.rb', line 4 def collection @collection end |
#element ⇒ Object (readonly)
Returns the value of attribute element
4 5 6 |
# File 'lib/gorillib/model/active_model_naming.rb', line 4 def element @element end |
#i18n_key ⇒ Object (readonly)
Returns the value of attribute i18n_key
4 5 6 |
# File 'lib/gorillib/model/active_model_naming.rb', line 4 def i18n_key @i18n_key end |
#namespace ⇒ Object
Returns the value of attribute namespace
3 4 5 |
# File 'lib/gorillib/model/active_model_naming.rb', line 3 def namespace @namespace end |
#param_key ⇒ Object (readonly)
Returns the value of attribute param_key
4 5 6 |
# File 'lib/gorillib/model/active_model_naming.rb', line 4 def param_key @param_key end |
#partial_path ⇒ Object (readonly)
Returns the value of attribute partial_path
4 5 6 |
# File 'lib/gorillib/model/active_model_naming.rb', line 4 def partial_path @partial_path end |
#singular ⇒ Object (readonly)
Returns the value of attribute singular
4 5 6 |
# File 'lib/gorillib/model/active_model_naming.rb', line 4 def singular @singular end |
Instance Method Details
#plural=(str) ⇒ Object
27 28 29 30 31 32 |
# 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 ⇒ Object
48 49 50 51 52 |
# 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 ⇒ Object
44 45 46 |
# File 'lib/gorillib/model/active_model_naming.rb', line 44 def singular_route_key inflector.singularize(route_key).freeze end |