Class: Rails::Surrender::Render::Count

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/surrender/render/count.rb

Overview

Rendering a count of resources.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ Count

Returns a new instance of Count.



10
11
12
# File 'lib/rails/surrender/render/count.rb', line 10

def initialize(resource)
  @resource = resource
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



8
9
10
# File 'lib/rails/surrender/render/count.rb', line 8

def resource
  @resource
end

Instance Method Details

#parseObject



14
15
16
17
# File 'lib/rails/surrender/render/count.rb', line 14

def parse
  count = resource.respond_to?(:count) ? resource.count : 1
  Response.new(data: { count: count })
end