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

Author:

  • Darthjee

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.

Parameters:

  • name (String, Symbol)

    name of the resource

  • options (Azeroth::Options)

    resource options



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

Returns:

  • (Hash)


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)

Returns:

  • (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

Returns:

  • (String)


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

Returns:

  • (String)


38
39
40
# File 'lib/azeroth/model.rb', line 38

def plural
  name.pluralize
end