class DataMiner

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 DataMiner::ActiveRecordClassMethods#data_miner Overview of how to define data miner scripts inside of ActiveRecord models.

Constants

INNER_SPACE
ONE_SPACE
VERSION

Attributes

logger[W]

Public Class Methods

compress_whitespace(str) click to toggle source

@private

# File lib/data_miner.rb, line 45
def compress_whitespace(str)
  str.gsub(INNER_SPACE, ONE_SPACE).strip
end
downcase(str) click to toggle source

@private

# File lib/data_miner.rb, line 35
def downcase(str)
  defined?(::UnicodeUtils) ? ::UnicodeUtils.downcase(str) : str.downcase
end
upcase(str) click to toggle source

@private

# File lib/data_miner.rb, line 40
def upcase(str)
  defined?(::UnicodeUtils) ? ::UnicodeUtils.upcase(str) : str.upcase
end

Public Instance Methods

logger() click to toggle source

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

@return [Logger]

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

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

@note Models won’t appear here until the files containing their data miner scripts have been require‘d.

@return [Set<String>]

# File lib/data_miner.rb, line 95
def model_names
  @model_names || ::Thread.exclusive do
    @model_names ||= ::Set.new
  end
end
run(model_names = DataMiner.model_names)

legacy

Alias for: start
start(model_names = DataMiner.model_names) click to toggle source

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

@param [optional, Array<String>] model_names Names of models to be run.

@return nil

# 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
Also aliased as: run