Class: LEWT::Store

Inherits:
Extension show all
Defined in:
lib/extensions/store.rb

Overview

The Store LEWT Extension handles persisting data across sessions. It hooks into the ‘process’ operation to obtain the raw extract data, likewise it hooks into ‘render’ to get the process data. Whilst in ‘render’ it also handles writing the data to the file-system, so to save data you must invoke it with the –render flag! The data is saved to some configurable paths (see source code).

Furthermore store can also re-extract previously persisted data from the file system for re-use! This is handy if you need to re-generate some output (ie: an invoice that required a quick edit), or if you would like to use store data built up overtime for bulk operations such as analytics & reporting.

Instance Attribute Summary

Attributes inherited from Extension

#command_name, #customers, #enterprise, #lewt_settings, #lewt_stash, #options

Instance Method Summary collapse

Methods inherited from Extension

#get_matched_customers, #lewt_extensions

Constructor Details

#initializeStore

Sets up this extensions command name and run-time options.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/extensions/store.rb', line 22

def initialize
  options = {
    :store_filename => {
      :definition => "File name to save as",
      :type => String
    },
    :store_hook => {
      :definition => "Tell store whether to save either the 'extract' or 'process' data",
      :default => "process",
      :type => String
    }
  }
  super({:cmd => "store", :options => options})
end

Instance Method Details

#extract(options) ⇒ Object

This method is not yet implemented. This method (should) extracts previously stored data for reuse.

options [Hash]

A hash that is passed to this extension by the main LEWT program containing ru-time options.



39
40
41
# File 'lib/extensions/store.rb', line 39

def extract( options )
  
end

#process(options, data) ⇒ Object

Captures the extract data and converts it to a YML string storing it as a property on this object. Returns an empty array so as not to interupt the process loop.

options [Hash]

A hash that is passed to this extension by the main LEWT program containing ru-time options.

data [Hash]

The extracted data as a hash.



47
48
49
50
# File 'lib/extensions/store.rb', line 47

def process( options, data )
  @extractData = data.to_yaml
  return []
end

#render(options, data) ⇒ Object

Captures proess data and converts it to a YML string. This method also handles the actual writing of data to the file system. The options ‘store_hook’ toggles exract or process targeting.

options [Hash]

A hash that is passed to this extension by the main LEWT program containing ru-time options.

data [Array]

The processed data as an array of hashes.



57
58
59
60
61
62
# File 'lib/extensions/store.rb', line 57

def render( options, data )
  @processData = data.to_yaml
  name = options[:store_filename]
  yml = options[:store_hook] == "extract" ? @extractData : @processData
  name != nil ? store(yml, name ) : [yml]
end