Sha256: df2e6f8ec4fa6b10674efddb62a60d35b0b6d3ea632d1cd2e5a2fe4f77943e85

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

require 'active_record'
require 'blockenspiel'

class DataMiner
  module ActiveRecordExtensions
    def data_miner(options = {}, &blk)
      ::DataMiner.instance.start_logging

      ::DataMiner.logger.debug "Database table `#{table_name}` doesn't exist. It might be created in the data_miner block, but if it's not, DataMiner probably won't work properly until you run a migration or otherwise fix the schema." unless table_exists?

      ::DataMiner.instance.resource_names.push self.name unless ::DataMiner.instance.resource_names.include? self.name

      # this is class_eval'ed here so that each ActiveRecord descendant has its own copy, or none at all
      class_eval do
        cattr_accessor :data_miner_config
        def self.data_miner_runs
          ::DataMiner::Run.scoped :conditions => { :resource_name => name }
        end
        def self.run_data_miner!(options = {})
          data_miner_config.run options
        end
        def self.execute_schema
          if schema = data_miner_config.steps.detect { |s| s.instance_of?(::DataMiner::Schema) }
            schema.run
          end
        end
      end

      if options[:append]
        self.data_miner_config ||= ::DataMiner::Config.new self
      else
        self.data_miner_config = ::DataMiner::Config.new self
      end

      ::Blockenspiel.invoke blk, data_miner_config

      data_miner_config.after_invoke
    end
  end
end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
data_miner-1.1.8 lib/data_miner/active_record_extensions.rb