Class: Transmutation::Field Private

Inherits:
Object
  • Object
show all
Defined in:
lib/transmutation/field.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.

Base class for a serializable field. Encapsulates the name, the precomputed JSON key, and the optional if:/unless: rendering conditions shared by attributes and associations.

Direct Known Subclasses

Association, Attribute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, **options, &block) ⇒ Field

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 Field.



11
12
13
14
15
16
17
# File 'lib/transmutation/field.rb', line 11

def initialize(name, **options, &block)
  @name = name
  @key = name.to_s.freeze
  @block = block
  @if = options[:if]
  @unless = options[:unless]
end

Instance Attribute Details

#keyObject (readonly)

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.



9
10
11
# File 'lib/transmutation/field.rb', line 9

def key
  @key
end

#nameObject (readonly)

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.



9
10
11
# File 'lib/transmutation/field.rb', line 9

def name
  @name
end

Instance Method Details

#render?(serializer) ⇒ Boolean

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.

Whether this field should be rendered for the given serializer instance.

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'lib/transmutation/field.rb', line 20

def render?(serializer)
  return false if @if && !evaluate(@if, serializer)
  return false if @unless && evaluate(@unless, serializer)

  true
end