Module: Unchained::Client::Mixins::Resource

Overview

The Resource mixin gives you access to a DSL that lets you define what the class should look like in the JSON response.

Usage:

class Guild
  include Unchained::Client::Mixins::Resource

  attribute :id, String
  attribute :name, String
  attribute :members, Integer, json: 'numberOfMembers'
end

Defined Under Namespace

Modules: ClassMethods Classes: Attribute

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



53
54
55
# File 'lib/unchained/client/mixins/resource.rb', line 53

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#to_sObject

Mostly just a helper method that you can override if you want to.



59
60
61
62
63
64
65
# File 'lib/unchained/client/mixins/resource.rb', line 59

def to_s
  attrs = self.class.attributes.map do |attr|
    "#{attr.name}=#{self.send(attr.name)}"
  end.join(', ')

  "[#{self.class.name.split('::').last}] #{attrs}"
end