Class: Super::Display::SchemaTypes::Built

Inherits:
Object
  • Object
show all
Defined in:
lib/super/display/schema_types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_nameObject (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

#typeObject (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

Returns:

  • (Boolean)


60
61
62
# File 'lib/super/display/schema_types.rb', line 60

def real?
  @real
end