Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-15 14:22:53 +01:00
dynamically set field attributes based on static list
Dieser Commit ist enthalten in:
Ursprung
b0f7fbf298
Commit
343f594f18
1 geänderte Dateien mit 44 neuen und 35 gelöschten Zeilen
|
@ -3,47 +3,56 @@
|
||||||
class CustomWizard::Field
|
class CustomWizard::Field
|
||||||
include ActiveModel::SerializerSupport
|
include ActiveModel::SerializerSupport
|
||||||
|
|
||||||
attr_reader :raw,
|
def self.attributes
|
||||||
:id,
|
%i{
|
||||||
:type,
|
raw
|
||||||
:required,
|
id
|
||||||
:value,
|
index
|
||||||
:label,
|
type
|
||||||
:description,
|
step
|
||||||
:image,
|
required
|
||||||
:key,
|
value
|
||||||
:validations,
|
description
|
||||||
:min_length,
|
image
|
||||||
:max_length,
|
key
|
||||||
:char_counter,
|
validations
|
||||||
:file_types,
|
min_length
|
||||||
:format,
|
max_length
|
||||||
:limit,
|
char_counter
|
||||||
:property,
|
file_types
|
||||||
:content
|
format
|
||||||
|
limit
|
||||||
|
property
|
||||||
|
content
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
attr_accessor :index,
|
def self.accessible_attributes
|
||||||
:step
|
%i{
|
||||||
|
index
|
||||||
|
step
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.excluded_attributes
|
||||||
|
%i{
|
||||||
|
label
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
attr_reader *(attributes - accessible_attributes - excluded_attributes)
|
||||||
|
attr_accessor *accessible_attributes
|
||||||
|
|
||||||
def initialize(attrs)
|
def initialize(attrs)
|
||||||
|
attrs.each do |k, v|
|
||||||
|
if self.singleton_class.attributes.include?(k.to_sym)
|
||||||
|
instance_variable_set("@#{k}", v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@raw = attrs || {}
|
@raw = attrs || {}
|
||||||
@id = attrs[:id]
|
|
||||||
@index = attrs[:index]
|
|
||||||
@type = attrs[:type]
|
|
||||||
@required = !!attrs[:required]
|
@required = !!attrs[:required]
|
||||||
@value = attrs[:value] || default_value
|
@value = attrs[:value] || default_value
|
||||||
@description = attrs[:description]
|
|
||||||
@image = attrs[:image]
|
|
||||||
@key = attrs[:key]
|
|
||||||
@validations = attrs[:validations]
|
|
||||||
@min_length = attrs[:min_length]
|
|
||||||
@max_length = attrs[:max_length]
|
|
||||||
@char_counter = attrs[:char_counter]
|
|
||||||
@file_types = attrs[:file_types]
|
|
||||||
@format = attrs[:format]
|
|
||||||
@limit = attrs[:limit]
|
|
||||||
@property = attrs[:property]
|
|
||||||
@content = attrs[:content]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def label
|
def label
|
||||||
|
|
Laden …
In neuem Issue referenzieren