Class: Super::Display::SchemaTypes
- Inherits:
-
Object
- Object
- Super::Display::SchemaTypes
show all
- Defined in:
- lib/super/display/schema_types.rb
Defined Under Namespace
Classes: Badge, 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.
116
117
118
119
|
# File 'lib/super/display/schema_types.rb', line 116
def initialize(fields:)
@actions_called = false
@fields = fields
end
|
Instance Method Details
#actions ⇒ Object
180
181
182
183
184
185
|
# File 'lib/super/display/schema_types.rb', line 180
def actions
@actions_called = true
Builder.new.computed.none.transform do
Partial.new("display_actions")
end
end
|
#actions_called? ⇒ Boolean
188
189
190
|
# File 'lib/super/display/schema_types.rb', line 188
def actions_called?
@actions_called
end
|
#badge(*builder_methods) ⇒ Object
171
172
173
174
175
176
177
178
|
# File 'lib/super/display/schema_types.rb', line 171
def badge(*builder_methods)
Useful::Deprecation["0.22"].deprecation_warning("#badge", "use #real or #computed instead, and return an instance of Super::Badge")
builder_methods = %i[real ignore_nil attribute] 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
|
#batch ⇒ Object
153
154
155
156
157
|
# File 'lib/super/display/schema_types.rb', line 153
def batch
real do |value|
Partial.new("batch_checkbox", locals: { value: value })
end
end
|
#computed(type = :attribute, &transform_block) ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/super/display/schema_types.rb', line 135
def computed(type = :attribute, &transform_block)
if type == :column
Useful::Deprecation["0.22"].deprecation_warning(":column", "use :attribute instead")
type = :attribute
end
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
149
150
151
|
# File 'lib/super/display/schema_types.rb', line 149
def manual(&transform_block)
real(:attribute, &transform_block)
end
|
#real(type = :attribute, &transform_block) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/super/display/schema_types.rb', line 121
def real(type = :attribute, &transform_block)
if type == :column
Useful::Deprecation["0.22"].deprecation_warning(":column", "use :attribute instead")
type = :attribute
end
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_text ⇒ Object
164
165
166
167
168
|
# File 'lib/super/display/schema_types.rb', line 164
def rich_text
computed do |value|
Partial.new("display_rich_text", locals: { rich_text: value })
end
end
|
#string ⇒ Object
159
|
# File 'lib/super/display/schema_types.rb', line 159
def string; real(&:to_s); end
|
#time ⇒ Object
162
|
# File 'lib/super/display/schema_types.rb', line 162
def time; real { |value| value.strftime("%H:%M:%S") }; end
|
#timestamp ⇒ Object
161
|
# File 'lib/super/display/schema_types.rb', line 161
def timestamp; real(&:to_s); end
|