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



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

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

#actions_called?Boolean

Returns:

  • (Boolean)


165
166
167
# File 'lib/super/display/schema_types.rb', line 165

def actions_called?
  @actions_called
end

#badge(*builder_methods) ⇒ Object



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

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

#batchObject



132
133
134
135
136
# File 'lib/super/display/schema_types.rb', line 132

def batch
  real do |value|
    Partial.new("batch_checkbox", locals: { value: value })
  end
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



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

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

#stringObject



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

def string; real(&:to_s); end

#timeObject



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

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

#timestampObject



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

def timestamp; real(&:to_s); end