Class: Azeroth::Model Private
- Inherits:
-
Object
- Object
- Azeroth::Model
- Defined in:
- lib/azeroth/model.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Model responsible for making the conection to the resource model class
Instance Method Summary collapse
-
#decorate(object) ⇒ Hash
private
Decorates object to return a hash.
-
#initialize(name, options) ⇒ Model
constructor
private
A new instance of Model.
-
#klass ⇒ Class
private
Resource class (real model class).
-
#name ⇒ String
private
Returns the name of the resource represented by the model.
-
#plural ⇒ String
private
Return the pluralized version of resource name.
Constructor Details
#initialize(name, options) ⇒ Model
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Model.
11 12 13 14 15 16 17 18 19 |
# File 'lib/azeroth/model.rb', line 11 def initialize(name, ) if name.is_a?(Class) @klass = name else @name = name.to_s end @options = end |
Instance Method Details
#decorate(object) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Decorates object to return a hash
Decorate uses klass::Decorator to decorate.
When no decorator has been defined, object will receive an #as_json
call instead
50 51 52 |
# File 'lib/azeroth/model.rb', line 50 def decorate(object) decorator_class.new(object).as_json end |
#klass ⇒ Class
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Resource class (real model class)
31 32 33 |
# File 'lib/azeroth/model.rb', line 31 def klass @klass ||= name.camelize.constantize end |
#name ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the name of the resource represented by the model
24 25 26 |
# File 'lib/azeroth/model.rb', line 24 def name @name ||= klass.name.gsub(/.*::/, '').underscore end |
#plural ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return the pluralized version of resource name
38 39 40 |
# File 'lib/azeroth/model.rb', line 38 def plural name.pluralize end |