Class: Ruote::Exp::ReadExpression
- Inherits:
-
FlowExpression
- Object
- FlowExpression
- Ruote::Exp::ReadExpression
- Defined in:
- lib/ruote/exp/fe_read.rb
Overview
Reads the content of a local file or a file reachable over http and places the content in a [process] variable or a [workitem] field.
Always attempts to parse the content as JSON. If the parsing fails, simply considers as plain text.
Ruote.process_definition do
read 'http://defs.example.org/filters/filter1.json', :to => 'x'
read 'http://defs.example.org/filters/filter1.json', :to => 'f:x'
read 'http://defs.example.org/filters/filter2.json', :to => 'v:y'
read 'filters/filter3.json', :to => 'f:y'
read 'texts/greetings${f:greeting_index}.txt', :to => 'f:greetings'
# ...
end
Constant Summary
Constants inherited from FlowExpression
FlowExpression::COMMON_ATT_KEYS
Instance Attribute Summary
Attributes inherited from FlowExpression
Instance Method Summary collapse
Methods inherited from FlowExpression
#ancestor?, #att, #attribute, #attribute_text, #attributes, #cancel, #compile_atts, #compile_variables, do_action, #do_apply, #do_cancel, #do_fail, #do_pause, #do_persist, #do_reply, #do_resume, #do_unpersist, #expand_atts, #fei, fetch, from_h, #handle_on_error, #has_attribute, #initial_persist, #initialize, #iterative_var_lookup, #launch_sub, #lookup_on_error, #lookup_val, #lookup_val_prefix, #lookup_variable, #name, names, #parent, #parent_id, #persist_or_raise, #reply_to_parent, #set_variable, #to_h, #tree, #tree_children, #try_persist, #try_unpersist, #unpersist_or_raise, #unset_variable, #update_tree, #variables
Methods included from WithMeta
Methods included from WithH
Constructor Details
This class inherits a constructor from Ruote::Exp::FlowExpression
Instance Method Details
#apply ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ruote/exp/fe_read.rb', line 48 def apply to = attribute('to') from = attribute('from') || attribute_text content = open(from).read rescue nil # should this happen in the worker loop ? thread out ? content = Rufus::Json.decode(content) rescue content set_vf(to, content) reply_to_parent(h.applied_workitem) end |
#reply(workitem) ⇒ Object
63 64 65 66 |
# File 'lib/ruote/exp/fe_read.rb', line 63 def reply(workitem) # empty, never called end |