Module: JSONAPI::Serializable::Resource::KeyFormat::DSL

Defined in:
lib/jsonapi/serializable/resource/key_format.rb

Overview

DSL extensions for automatic key transformations.

Instance Method Summary collapse

Instance Method Details

#attribute(name, options = {}, &block) ⇒ Object

Handles automatic key transformation for attributes.



34
35
36
37
# File 'lib/jsonapi/serializable/resource/key_format.rb', line 34

def attribute(name, options = {}, &block)
  block ||= proc { @object.public_send(name) }
  super(key_format.call(name), options, &block)
end

#inherited(klass) ⇒ Object



28
29
30
31
# File 'lib/jsonapi/serializable/resource/key_format.rb', line 28

def inherited(klass)
  super
  klass.key_format = key_format
end

#relationship(name, options = {}, &block) ⇒ Object

Handles automatic key transformation for relationships.



40
41
42
43
44
45
46
# File 'lib/jsonapi/serializable/resource/key_format.rb', line 40

def relationship(name, options = {}, &block)
  rel_block = proc do
    data(options[:class]) { @object.public_send(name) }
    instance_eval(&block) unless block.nil?
  end
  super(key_format.call(name), options, &rel_block)
end