Module: Drillbit::Serializers::JsonApi::ClassMethods

Defined in:
lib/drillbit/serializers/json_api.rb

Instance Method Summary collapse

Instance Method Details

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



23
24
25
26
# File 'lib/drillbit/serializers/json_api.rb', line 23

def attribute(name, _options = {}, &block)
  block                                         ||= proc { @object.public_send(name) }
  attribute_blocks[name.to_s.tr('_', '-').to_sym] = block
end

#type_blockObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/drillbit/serializers/json_api.rb', line 7

def type_block
  proc {
    @object
      .class
      .name
      .gsub(/\A[^:]+::/, '')
      .split('::')
      .reverse
      .join('::')
      .tableize
      .dasherize
      .tr('/', '-')
      .pluralize
  }
end