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.



43
44
45
46
47
48
49
# File 'lib/super/display/schema_types.rb', line 43

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.



53
54
55
# File 'lib/super/display/schema_types.rb', line 53

def attribute_name
  @attribute_name
end

#typeObject (readonly)

Returns the value of attribute type.



52
53
54
# File 'lib/super/display/schema_types.rb', line 52

def type
  @type
end

Instance Method Details

#present(attribute_name, value = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/super/display/schema_types.rb', line 55

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)


51
# File 'lib/super/display/schema_types.rb', line 51

def real?; @real; end