Class: Wrappix::Templates::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/wrappix/templates/collection.rb

Class Method Summary collapse

Class Method Details

.render(module_name, _config) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/wrappix/templates/collection.rb', line 7

def self.render(module_name, _config)
  <<~RUBY
    # frozen_string_literal: true

    module #{module_name}
      class Collection
        attr_reader :data, :next_href

        def self.from_response(response_body, type:)
          new(
            data: response_body[:data]&.map { |attrs| type.new(attrs) },
            next_href: response_body[:next_href]
          )
        end

        def initialize(data:, next_href:)
          @data = data
          @next_href = next_href
        end
      end
    end
  RUBY
end