Class: Super::Display::SchemaTypes::Built
- Inherits:
-
Object
- Object
- Super::Display::SchemaTypes::Built
- Defined in:
- lib/super/display/schema_types.rb
Instance Attribute Summary collapse
-
#attribute_name ⇒ Object
readonly
Returns the value of attribute attribute_name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(real:, type:, ignore_nil:, attribute_name:, &transform_block) ⇒ Built
constructor
A new instance of Built.
- #present(attribute_name, value = nil) ⇒ Object
- #real? ⇒ Boolean
Constructor Details
#initialize(real:, type:, ignore_nil:, attribute_name:, &transform_block) ⇒ Built
Returns a new instance of Built.
52 53 54 55 56 57 58 |
# File 'lib/super/display/schema_types.rb', line 52 def initialize(real:, type:, ignore_nil:, attribute_name:, &transform_block) @real = real @type = type @ignore_nil = ignore_nil @attribute_name = attribute_name @transform_block = transform_block end |
Instance Attribute Details
#attribute_name ⇒ Object (readonly)
Returns the value of attribute attribute_name.
64 65 66 |
# File 'lib/super/display/schema_types.rb', line 64 def attribute_name @attribute_name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
63 64 65 |
# File 'lib/super/display/schema_types.rb', line 63 def type @type end |
Instance Method Details
#present(attribute_name, value = nil) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/super/display/schema_types.rb', line 66 def present(attribute_name, value = nil) if @transform_block.nil? if attribute_name raise Error::ArgumentError, "Transformation block is not set for attribute: #{attribute_name}" else raise Error::ArgumentError, "Transformation block is not set!" end end return nil if value.nil? && @ignore_nil if @type == :none @transform_block.call else @transform_block.call(value) end end |
#real? ⇒ Boolean
60 61 62 |
# File 'lib/super/display/schema_types.rb', line 60 def real? @real end |