Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 01:10:28 +01:00
Add boolean connector
Dieser Commit ist enthalten in:
Ursprung
7cc84e4a25
Commit
5b5bbd0e1a
3 geänderte Dateien mit 12 neuen und 9 gelöschten Zeilen
|
@ -31,7 +31,8 @@ const connectors = {
|
|||
'less',
|
||||
'greater_or_equal',
|
||||
'less_or_equal',
|
||||
'regex'
|
||||
'regex',
|
||||
'boolean'
|
||||
],
|
||||
output: [
|
||||
'then',
|
||||
|
|
|
@ -176,6 +176,7 @@ en:
|
|||
less_or_equal: '<='
|
||||
regex: '=~'
|
||||
association: '→'
|
||||
boolean: 'is'
|
||||
|
||||
action:
|
||||
header: "Actions"
|
||||
|
|
|
@ -14,7 +14,8 @@ class CustomWizard::Mapper
|
|||
less: '<',
|
||||
greater_or_equal: '>=',
|
||||
less_or_equal: '<=',
|
||||
regex: '=~'
|
||||
regex: '=~',
|
||||
boolean: '=='
|
||||
}
|
||||
|
||||
def initialize(params)
|
||||
|
@ -85,14 +86,12 @@ class CustomWizard::Mapper
|
|||
|
||||
def validate_pairs(pairs)
|
||||
pairs.all? do |pair|
|
||||
key = map_field(pair['key'], pair['key_type'])
|
||||
connector = pair['connector']
|
||||
operator = map_operator(connector)
|
||||
value = cast_value(
|
||||
key,
|
||||
map_field(pair['value'], pair['value_type']),
|
||||
connector
|
||||
)
|
||||
key = map_field(pair['key'], pair['key_type'])
|
||||
value = cast_value(map_field(pair['value'], pair['value_type']), key, connector)
|
||||
|
||||
byebug
|
||||
|
||||
begin
|
||||
cast_result(key.public_send(operator, value), connector)
|
||||
|
@ -102,9 +101,11 @@ class CustomWizard::Mapper
|
|||
end
|
||||
end
|
||||
|
||||
def cast_value(key, value, connector)
|
||||
def cast_value(value, key, connector)
|
||||
if connector == 'regex'
|
||||
Regexp.new(value)
|
||||
elsif connector == 'boolean'
|
||||
ActiveRecord::Type::Boolean.new.cast(value)
|
||||
else
|
||||
if key.is_a?(String)
|
||||
value.to_s
|
||||
|
|
Laden …
In neuem Issue referenzieren