Class: Super::Display::SchemaTypes::Built
- Inherits:
-
Object
- Object
- Super::Display::SchemaTypes::Built
- Defined in:
- lib/super/display/schema_types.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(real:, type:, ignore_nil:, &transform_block) ⇒ Built
constructor
A new instance of Built.
- #present(attribute_name, value = nil) ⇒ Object
- #real? ⇒ Boolean
Constructor Details
#initialize(real:, type:, ignore_nil:, &transform_block) ⇒ Built
Returns a new instance of Built.
35 36 37 38 39 40 |
# File 'lib/super/display/schema_types.rb', line 35 def initialize(real:, type:, ignore_nil:, &transform_block) @real = real @type = type @ignore_nil = ignore_nil @transform_block = transform_block end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
43 44 45 |
# File 'lib/super/display/schema_types.rb', line 43 def type @type end |
Instance Method Details
#present(attribute_name, value = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/super/display/schema_types.rb', line 45 def present(attribute_name, value = nil) if @transform_block.nil? if attribute_name raise Error::ArgumentError, "Transformation block is not set for column: #{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
42 |
# File 'lib/super/display/schema_types.rb', line 42 def real?; @real; end |