Class: Super::Display::SchemaTypes

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

Defined Under Namespace

Classes: Builder, Built

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initialize(fields:) ⇒ SchemaTypes

Returns a new instance of SchemaTypes.



85
86
87
88
# File 'lib/super/display/schema_types.rb', line 85

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

Instance Method Details

#actionsObject



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

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

#actions_called?Boolean

Returns:

  • (Boolean)


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

def actions_called?
  @actions_called
end

#batchObject



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

def batch
  real do |value|
    Partial.new("batch_checkbox", locals: {value: value})
  end
end

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



99
100
101
102
103
104
105
106
# File 'lib/super/display/schema_types.rb', line 99

def computed(type = :attribute, &transform_block)
  TYPES
    .case(type)
    .when(:attribute) { Builder.new.computed.ignore_nil.attribute.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



108
109
110
# File 'lib/super/display/schema_types.rb', line 108

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

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



90
91
92
93
94
95
96
97
# File 'lib/super/display/schema_types.rb', line 90

def real(type = :attribute, &transform_block)
  TYPES
    .case(type)
    .when(:attribute) { Builder.new.real.ignore_nil.attribute.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



130
131
132
133
134
# File 'lib/super/display/schema_types.rb', line 130

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

#stringObject



118
119
120
# File 'lib/super/display/schema_types.rb', line 118

def string
  real(&:to_s)
end

#timeObject



126
127
128
# File 'lib/super/display/schema_types.rb', line 126

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

#timestampObject



122
123
124
# File 'lib/super/display/schema_types.rb', line 122

def timestamp
  real(&:to_s)
end