0
0
Fork 1
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:
Faizaan Gagan 2021-05-16 17:22:46 +05:30
Ursprung b0f7fbf298
Commit 343f594f18

Datei anzeigen

@ -3,47 +3,56 @@
class CustomWizard::Field
include ActiveModel::SerializerSupport
attr_reader :raw,
:id,
:type,
:required,
:value,
:label,
:description,
:image,
:key,
:validations,
:min_length,
:max_length,
:char_counter,
:file_types,
:format,
:limit,
:property,
:content
def self.attributes
%i{
raw
id
index
type
step
required
value
description
image
key
validations
min_length
max_length
char_counter
file_types
format
limit
property
content
}
end
attr_accessor :index,
:step
def self.accessible_attributes
%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)
attrs.each do |k, v|
if self.singleton_class.attributes.include?(k.to_sym)
instance_variable_set("@#{k}", v)
end
end
@raw = attrs || {}
@id = attrs[:id]
@index = attrs[:index]
@type = attrs[:type]
@required = !!attrs[:required]
@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
def label