Class: Super::Display::SchemaTypes

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

Defined Under Namespace

Classes: Badge, Builder, Built

Constant Summary collapse

TYPES =
Useful::Enum.new(:column, :record, :none)

Instance Method Summary collapse

Constructor Details

#initialize(fields:) ⇒ SchemaTypes

Returns a new instance of SchemaTypes.



105
106
107
108
# File 'lib/super/display/schema_types.rb', line 105

def initialize(fields:)
  @actions_called = false
  @fields = fields
end

Instance Method Details

#actionsObject



151
152
153
154
155
156
# File 'lib/super/display/schema_types.rb', line 151

def actions
  @actions_called = true
  Builder.new.computed.none.transform do
    Partial.new("display_actions")
  end
end

#actions_called?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/super/display/schema_types.rb', line 159

def actions_called?
  @actions_called
end

#badge(*builder_methods) ⇒ Object



143
144
145
146
147
148
149
# File 'lib/super/display/schema_types.rb', line 143

def badge(*builder_methods)
  builder_methods = %i[real ignore_nil column] if builder_methods.empty?
  builder = builder_methods.each_with_object(Builder.new) do |builder_method, builder|
    builder.public_send(builder_method)
  end
  Badge.new(builder)
end

#computed(type = :column, &transform_block) ⇒ Object



119
120
121
122
123
124
125
126
# File 'lib/super/display/schema_types.rb', line 119

def computed(type = :column, &transform_block)
  TYPES
    .case(type)
    .when(:column) { Builder.new.computed.ignore_nil.column.transform(&transform_block) }
    .when(:record) { Builder.new.computed.ignore_nil.record.transform(&transform_block) }
    .when(:none)   { Builder.new.computed.ignore_nil.none.transform(&transform_block) }
    .result
end

#manual(&transform_block) ⇒ Object



128
129
130
# File 'lib/super/display/schema_types.rb', line 128

def manual(&transform_block)
  real(:column, &transform_block)
end

#real(type = :column, &transform_block) ⇒ Object



110
111
112
113
114
115
116
117
# File 'lib/super/display/schema_types.rb', line 110

def real(type = :column, &transform_block)
  TYPES
    .case(type)
    .when(:column) { Builder.new.real.ignore_nil.column.transform(&transform_block) }
    .when(:record) { Builder.new.real.ignore_nil.record.transform(&transform_block) }
    .when(:none)   { Builder.new.real.ignore_nil.none.transform(&transform_block) }
    .result
end

#rich_textObject



137
138
139
140
141
# File 'lib/super/display/schema_types.rb', line 137

def rich_text
  computed do |value|
    Partial.new("display_rich_text", locals: { rich_text: value })
  end
end

#stringObject



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

def string; real(&:to_s); end

#timeObject



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

def time; real { |value| value.strftime("%H:%M:%S") }; end

#timestampObject



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

def timestamp; real(&:to_s); end