Class: Alba::Layout Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/alba/layout.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Layout serialization

Instance Method Summary collapse

Constructor Details

#initialize(file:, inline:) ⇒ Layout

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Layout.



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/alba/layout.rb', line 16

def initialize(file:, inline:)
  @body = if file
            raise ArgumentError, 'File layout must be a String representing filename' unless file.is_a?(String)

            file
          elsif inline
            raise ArgumentError, 'Inline layout must be a Proc returning a Hash or a String' unless inline.is_a?(Proc)

            inline
          else
            raise ArgumentError, 'Layout must be either String or Proc'
          end
end

Instance Method Details

#serialize(resource:, serialized_json:, binding:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Serialize within layout



35
36
37
38
39
40
41
42
43
44
# File 'lib/alba/layout.rb', line 35

def serialize(resource:, serialized_json:, binding:)
  @resource = resource
  @serialized_json = serialized_json

  if @body.is_a?(String)
    serialize_within_string_layout(binding)
  else
    serialize_within_inline_layout
  end
end