0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 09:20:29 +01:00

Add boolean connector

Dieser Commit ist enthalten in:
Angus McLeod 2020-04-30 19:17:37 +10:00
Ursprung 7cc84e4a25
Commit 5b5bbd0e1a
3 geänderte Dateien mit 12 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -31,7 +31,8 @@ const connectors = {
'less', 'less',
'greater_or_equal', 'greater_or_equal',
'less_or_equal', 'less_or_equal',
'regex' 'regex',
'boolean'
], ],
output: [ output: [
'then', 'then',

Datei anzeigen

@ -176,6 +176,7 @@ en:
less_or_equal: '<=' less_or_equal: '<='
regex: '=~' regex: '=~'
association: '→' association: '→'
boolean: 'is'
action: action:
header: "Actions" header: "Actions"

Datei anzeigen

@ -14,7 +14,8 @@ class CustomWizard::Mapper
less: '<', less: '<',
greater_or_equal: '>=', greater_or_equal: '>=',
less_or_equal: '<=', less_or_equal: '<=',
regex: '=~' regex: '=~',
boolean: '=='
} }
def initialize(params) def initialize(params)
@ -85,14 +86,12 @@ class CustomWizard::Mapper
def validate_pairs(pairs) def validate_pairs(pairs)
pairs.all? do |pair| pairs.all? do |pair|
key = map_field(pair['key'], pair['key_type'])
connector = pair['connector'] connector = pair['connector']
operator = map_operator(connector) operator = map_operator(connector)
value = cast_value( key = map_field(pair['key'], pair['key_type'])
key, value = cast_value(map_field(pair['value'], pair['value_type']), key, connector)
map_field(pair['value'], pair['value_type']),
connector byebug
)
begin begin
cast_result(key.public_send(operator, value), connector) cast_result(key.public_send(operator, value), connector)
@ -102,9 +101,11 @@ class CustomWizard::Mapper
end end
end end
def cast_value(key, value, connector) def cast_value(value, key, connector)
if connector == 'regex' if connector == 'regex'
Regexp.new(value) Regexp.new(value)
elsif connector == 'boolean'
ActiveRecord::Type::Boolean.new.cast(value)
else else
if key.is_a?(String) if key.is_a?(String)
value.to_s value.to_s