Class: Azeroth::Model Private

Inherits:
Object
  • Object
show all
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

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, options)
  if name.is_a?(Class)
    @klass = name
  else
    @name = name.to_s
  end

  @options = 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

#klassClass

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

#nameString

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

#pluralString

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