class Mushy::WriteFile

Public Class Methods

details() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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

Public Instance Methods

process(event, config) click to toggle source
# 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] }

  {
    file: Mushy::Ls.new.process({}, { path: file })[0]
  }
end