Class: DataMiner

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/data_miner.rb,
lib/data_miner/step.rb,
lib/data_miner/script.rb,
lib/data_miner/version.rb,
lib/data_miner/step/sql.rb,
lib/data_miner/attribute.rb,
lib/data_miner/step/test.rb,
lib/data_miner/step/import.rb,
lib/data_miner/step/process.rb,
lib/data_miner/active_record_class_methods.rb

Overview

A singleton class that holds global configuration for data mining.

All of its instance methods are delegated to DataMiner.instance, so you can call DataMiner.model_names, for example.

See Also:

Defined Under Namespace

Modules: ActiveRecordClassMethods Classes: Attribute, Script, Step

Constant Summary

INNER_SPACE =
/[ ]+/
ONE_SPACE =
' '
VERSION =
'3.0.0'

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Logger) logger

Where DataMiner logs to. Defaults to Rails.logger or ActiveRecord::Base.logger if either is available.

Returns:

  • (Logger)


77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/data_miner.rb', line 77

def logger
  @logger || ::Thread.exclusive do
    @logger ||= if defined?(::Rails)
      ::Rails.logger
    elsif defined?(::ActiveRecord) and active_record_logger = ::ActiveRecord::Base.logger
      active_record_logger
    else
      require 'logger'
      ::Logger.new $stderr
    end
  end
end

Instance Method Details

- (Set<String>) model_names

Note:

Models won't appear here until the files containing their data miner scripts have been require'd.

Names of the models that have defined a data miner script.

Returns:

  • (Set<String>)


95
96
97
98
99
# File 'lib/data_miner.rb', line 95

def model_names
  @model_names || ::Thread.exclusive do
    @model_names ||= ::Set.new
  end
end

- (Object) start(model_names = DataMiner.model_names) Also known as: run

Run data miner scripts on models identified by their names. Defaults to all models.

Parameters:

  • model_names (optional, Array<String>) (defaults to: DataMiner.model_names)

    Names of models to be run.

Returns:

  • nil



62
63
64
65
66
67
68
69
# File 'lib/data_miner.rb', line 62

def start(model_names = DataMiner.model_names)
  Script.uniq do
    model_names.map do |model_name|
      model_name.constantize.run_data_miner!
    end
  end
  nil
end