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
Public Class Methods
@private
# File lib/data_miner.rb, line 45 def compress_whitespace(str) str.gsub(INNER_SPACE, ONE_SPACE).strip end
@private
# File lib/data_miner.rb, line 35 def downcase(str) defined?(::UnicodeUtils) ? ::UnicodeUtils.downcase(str) : str.downcase end
@private
# File lib/data_miner.rb, line 40 def upcase(str) defined?(::UnicodeUtils) ? ::UnicodeUtils.upcase(str) : str.upcase end
Public Instance Methods
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
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 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