Class: Transmutation::Field Private
- Inherits:
-
Object
- Object
- Transmutation::Field
- 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
Instance Attribute Summary collapse
- #key ⇒ Object readonly private
- #name ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(name, **options, &block) ⇒ Field
constructor
private
A new instance of Field.
-
#render?(serializer) ⇒ Boolean
private
Whether this field should be rendered for the given serializer instance.
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, **, &block) @name = name @key = name.to_s.freeze @block = block @if = [:if] @unless = [:unless] end |
Instance Attribute Details
#key ⇒ Object (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 |
#name ⇒ Object (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.
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 |