We put the whole aasm block in string and eval it in payment_request model. Here is the def:
class PaymentRequest < :ActiveRecord::Base
include AASM
def self.load_wf_spec(wf_spec, wf_def_name)
eval("aasm(:#{wf_def_name}) :column => 'wf_state' {#{wf_spec}}")
end
end
The error is:
Failure/Error: eval("aasm(:#{wf_def_name}) :column => 'wf_state' {#{wf_spec}}")
SyntaxError:
(eval):1: syntax error, unexpected ':', expecting end-of-input
aasm(:test) :column => 'wf_state' {state :...
^
# ./app/models/payment_requestx/payment_request.rb:11:in `eval'
Here is the value of the variable:
wf_def_name = 'test'
wf_spec = "state :initial_state, :initial => true
state :ceo_reviewing
state :approved
state :stamped
state :paid
state :rejected
event :submit_test do
transitions :from => :initial_state, :to => :ceo_reviewing
end
event :ceo_approve_test do
transitions :from => :ceo_reviewing, :to => :approved
end
event :ceo_reject_test do
transitions :from => :ceo_reviewing, :to => :rejected
end
event :ceo_rewind_test do
transitions :from => :ceo_reviewing, :to => :initial_state
end
event :stamp_test do
transitions :from => :approved, :to => :stamped
end
event :pay_test do
transitions :from => :stamped, :to => :paid
end"
If removing (:test)', then the same error points to next:
Failure/Error: eval("aasm :column => 'wf_state' {#{wf_spec}}")
SyntaxError:
(eval):1: syntax error, unexpected '{', expecting end-of-input
aasm :column => 'wf_state' {state :initial_state, :initial => true
^
# ./app/models/payment_requestx/payment_request.rb:11:in `eval'
What is missing in the eval?
Here is what it works:
eval("aasm(:#{wf_def_name}, :column => 'wf_state') {#{def_string}}")
Related
In Typescript, Conditional Type splits "function returning boolean" () => boolean into "function returning true unions function returning false" () => true | () => false.
Could anyone explain why, and any solution to keep its returning type as "boolean"?
Example:
type A<U, E> = U extends E ? () => U : () => U;
const a: A<boolean, string> = () => Math.random() < 0.5;
Compile Error:
TS2322: Type '() => boolean' is not assignable to type '(() => false) | (() => true)'.
Type '() => boolean' is not assignable to type '() => false'.
Type 'boolean' is not assignable to type 'false'.
Here is the response i receive after send every successful sms. Output of php code print_r($MessageResult); is give below.
MessageBird\Objects\Message Object
(
[id:protected] => op34f300d57a4217xc9d48be7b890fd4
[href:protected] => https://rest.messagebird.com/messages/ae3956ccd57af2f7939d48be7b891qd4
[type] => sms
[originator] => +12223334444
[body] => sms text body is here
[typeDetails] => stdClass Object
(
)
[datacoding] => plain
[mclass] => 1
[scheduledDatetime] =>
[createdDatetime:protected] => 2021-06-25T18:55:38+00:00
[recipients] => stdClass Object
(
[totalCount] => 1
[totalDeliveryFailedCount] => 0
[items] => Array
(
[0] => MessageBird\Objects\Recipient Object
(
[recipient] => 19998886666
[status] => sent
[statusDatetime] => 2021-06-25T18:55:38+00:00
)
)
)
[reportUrl] =>
)
I get correct value for php code
echo $MessageResult->body
But I have tried by php code echo $MessageResult->id; and get error: Fatal error: Uncaught Error: Cannot access protected property MessageBird\Objects\Message::$id
My question is, How do i read id value? (which is here op34f300d57a4217xc9d48be7b890fd4)
PL statement:
sca.pac_age_web_infm_supl.pro_gera_ssos_infm_supl(
i_cod_un_cons => :i_cod_un_cons (float),
i_num_cli => :i_num_cli (float),
i_nom_sist_orig => :i_nom_sist_orig (string),
i_cod_tipo_aces => :i_cod_tipo_aces (string),
i_cod_tipo_sol => :i_cod_tipo_sol (string),
i_cod_tipo_ger => :i_cod_tipo_ger (string),
i_ano_emis => :i_ano_emis (float),
i_qtd_mes_emis => :i_qtd_mes_emis (float),
i_cod_tipo_emis => :i_cod_tipo_emis (string),
i_cod_email => :i_cod_email (string),
i_cod_tipo_vin => :i_cod_tipo_vin (string),
i_cod_tipo_rel => :i_cod_tipo_rel (string),
i_sta_cobr_emis => :i_sta_cobr_emis (string),
i_vlr_cobr_emis => :i_vlr_cobr_emis (float),
o_cod_cpu_os => :o_cod_cpu_os,
o_num_seq_oper_os => :o_num_seq_oper_os,
o_num_seq_ger_os => :o_num_seq_ger_os,
o_cntd_arq => :o_cntd_arq,
o_cursor => :o_cursor,
o_msg_erro => :o_msg_erro);
end;
NodeJS function:
var sql = 'BEGIN PAC_AGE_WEB_INFM_SUPL.PRO_GERA_SSOS_INFM_SUPL(:i_cod_un_cons, :i_num_cli, :i_nom_sist_orig, :i_cod_tipo_aces, :i_cod_tipo_sol, :i_cod_tipo_ger, :i_ano_emis, :i_qtd_mes_emis, :i_cod_tipo_emis, :i_cod_email, :i_cod_tipo_vin, :i_cod_tipo_rel, :i_sta_cobr_emis, :i_vlr_cobr_emis, :o_cod_cpu_os, :o_num_seq_oper_os, :o_num_seq_ger_os, :o_cntd_arq, :o_cursor, :o_msg_erro); END;';
Any tips on why my func returning ORA-01036?
All my bindvards correctly typed.
Missing colon, here:
:i_sta_cobr_emis, i_vlr_cobr_emis, :o_cod_cpu_os
^
|
Solved by droping the object and recompiling it. Thanks, guys!
I am trying to call the recursive function in my code. The loop executing first time, but recursive function which is called inside the function is not working.
Here is my code :
function buildDynamicMenu(elements,parentId)
{
branch =new Array();
elements.forEach(function(element){
if (element['parent_id'] == parentId) {
children = buildDynamicMenu(elements, element['menu_id']); //Recursive function not working
if (children) {
element['children'] =children;
}
branch = element;
}
});
return branch;
}
var parentId=0;
buildDynamicMenu(data); // Array data
I have added sample array which I am using for this logic, array has menu and Submenu Id, we have to call recursive function to loop through all sub array
Array
(
[0] => Array
(
[menu_id] => 1
[menu_name] => Home
[parent_id] => 0
[link] => #home
)
[1] => Array
(
[menu_id] => 2
[menu_name] => Web development
[parent_id] => 0
[link] => #web-dev
)
[2] => Array
(
[menu_id] => 3
[menu_name] => WordPress Development
[parent_id] => 2
[link] => #wp-dev
)
[3] => Array
(
[menu_id] => 4
[menu_name] => About w3school.info
[parent_id] => 2
[link] => #w3school-info
)
[4] => Array
(
[menu_id] => 7
[menu_name] => Javascript
[parent_id] => 2
[link] => #
)
[5] => Array
(
[menu_id] => 8
[menu_name] => Plugins
[parent_id] => 7
[link] => #plugin-dev
)
)
seems like this doesn't have a pointed buildDynamicMenu export. check if there is one in 'this'. try to assign the buildDynamicMenu function to some const and perform call to it.
Ok here is my demo func working very well in nodejs typescript:
function recursieve (p) {
console.log('in recursieve ', p);
if (p > 0) {
recursieve (--p);
} } recursieve (10);// rec call
So in my opinion there are two problems in your code:
1. 'this' was not pointed to the function.
2. recursieve condition, like the elements is empty, or id is no match.
The Nest Protect (smoke and CO alarm) can measure temperature and humidity but neither the official or unofficial API's appear to allow access to this data. Is anyone working on a work around? Any line of sight to accessing this data? Suggestions? Thanks!
$infos = (object) array(
'current_state' => (object) array(
'mode' => $mode,
'temperature' => $this->temperatureInUserScale((float) $this->last_status->shared->{$serial_number}->current_temperature),
'humidity' => $this->last_status->device->{$serial_number}->current_humidity,
'ac' => $this->last_status->shared->{$serial_number}->hvac_ac_state,
'heat' => $this->last_status->shared->{$serial_number}->hvac_heater_state,
'alt_heat' => $this->last_status->shared->{$serial_number}->hvac_alt_heat_state,
'fan' => $this->last_status->shared->{$serial_number}->hvac_fan_state,
'auto_away' => $this->last_status->shared->{$serial_number}->auto_away, // -1 when disabled, 0 when enabled (thermostat can set auto-away), >0 when enabled and active (thermostat is currently in auto-away mode)
'manual_away' => $manual_away,
'leaf' => $this->last_status->device->{$serial_number}->leaf,
'battery_level' => $this->last_status->device->{$serial_number}->battery_level
),
'target' => (object) array(
'mode' => $target_mode,
'temperature' => $target_temperatures,
'time_to_target' => $this->last_status->device->{$serial_number}->time_to_target,
Add this:
'humidity' => $this->last_status->device->{$serial_number}->target_humidity, //added by Rick Ammazzini
'humidity_enabled' => $this->last_status->device->{$serial_number}->target_humidity_enabled //added by Rick Ammazzini
),
'serial_number' => $this->last_status->device->{$serial_number}->serial_number,
'scale' => $this->last_status->device->{$serial_number}->temperature_scale,
'location' => $structure,
'line_power_present' => $this->last_status->device->{$serial_number}->line_power_present,
'network' => $this->getDeviceNetworkInfo($serial_number),
'name' => !empty($this->last_status->shared->{$serial_number}->name) ? $this->last_status->shared->{$serial_number}->name : DEVICE_WITH_NO_NAME,
'where' => isset($this->last_status->device->{$serial_number}->where_id) ? isset($this->where_map[$this->last_status->device->{$serial_number}->where_id]) ? $this->where_map[$this->last_status->device->{$serial_number}->where_id] : $this->last_status->device->{$serial_number}->where_id : ""
);
if($this->last_status->device->{$serial_number}->has_humidifier) {
$infos->current_state->humidifier= $this->last_status->device->{$serial_number}->humidifier_state;
$infos->target->humidity = $this->last_status->device->{$serial_number}->target_humidity;
$infos->target->humidity_enabled = $this->last_status->device->{$serial_number}->target_humidity_enabled;
}
return $infos;
}