Class: Mushy::WriteFile
- Inherits:
-
Flux
- Object
- Flux
- Mushy::WriteFile
show all
- Defined in:
- lib/mushy/fluxs/write_file.rb
Instance Attribute Summary
Attributes inherited from Flux
#config, #id, #masher, #parent_fluxs, #subscribed_to, #type
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Flux
#convert_this_to_an_array, #convert_to_symbolized_hash, #execute, #execute_single_event, #group_these_results, #guard, inherited, #initialize, #join_these_results, #limit_these_results, #merge_these_results, #model_these_results, #outgoing_split_these_results, #shape_these, #sort_these_results, #standardize_these
Constructor Details
This class inherits a constructor from Mushy::Flux
Class Method Details
.details ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/mushy/fluxs/write_file.rb', line 5
def self.details
{
name: 'WriteFile',
description: 'Write a file.',
config: file_saving_config.merge({
data: {
description: 'The text to write. You can use Liquid templating here to pull data from the event, or write hardcoded data.',
type: 'text',
value: '{{data}}',
},
}),
}
end
|
.file_saving_config ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/mushy/fluxs/write_file.rb', line 19
def self.file_saving_config
{
name: {
description: 'The name of the file.',
type: 'text',
value: 'file.csv',
},
directory: {
description: 'The directory in which to write the file. Leave blank for the current directory.',
shrink: true,
type: 'text',
value: '',
},
}
end
|
.get_file_from(config) ⇒ Object
35
36
37
38
39
|
# File 'lib/mushy/fluxs/write_file.rb', line 35
def self.get_file_from config
file = config[:name]
file = File.join(config[:directory], file) if config[:directory].to_s != ''
file
end
|
Instance Method Details
#process(event, config) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/mushy/fluxs/write_file.rb', line 41
def process event, config
file = self.class.get_file_from config
File.open(file, 'w') { |f| f.write config[:data] }
{}
end
|