Module: DataMiner::ActiveRecordClassMethods
- Defined in:
- lib/data_miner/active_record_class_methods.rb
Overview
Class methods that are mixed into models (i.e. ActiveRecord::Base)
Instance Method Summary collapse
-
#data_miner(options = {}) { ... } ⇒ nil
Define a data miner script.
-
#data_miner_runs ⇒ ActiveRecord::Relation
Access to recordkeeping.
-
#data_miner_script ⇒ DataMiner::Script
Access this model’s script.
-
#run_data_miner! ⇒ DataMiner::Run
Run this model’s script.
-
#run_data_miner_on_parent_associations! ⇒ Array<DataMiner::Run>
Run the data miner scripts of parent associations.
Instance Method Details
#data_miner(options = {}) { ... } ⇒ nil
Define a data miner script.
99 100 101 102 103 104 105 |
# File 'lib/data_miner/active_record_class_methods.rb', line 99 def data_miner( = {}, &blk) unless [:append] @data_miner_script = nil end data_miner_script.append_block blk nil end |
#data_miner_runs ⇒ ActiveRecord::Relation
Access to recordkeeping.
18 19 20 |
# File 'lib/data_miner/active_record_class_methods.rb', line 18 def data_miner_runs DataMiner::Run.scoped :conditions => { :model_name => name } end |
#data_miner_script ⇒ DataMiner::Script
Access this model’s script.
9 10 11 12 13 |
# File 'lib/data_miner/active_record_class_methods.rb', line 9 def data_miner_script @data_miner_script || ::Thread.exclusive do @data_miner_script ||= DataMiner::Script.new(self) end end |
#run_data_miner! ⇒ DataMiner::Run
Run this model’s script.
25 26 27 |
# File 'lib/data_miner/active_record_class_methods.rb', line 25 def run_data_miner! data_miner_script.start end |
#run_data_miner_on_parent_associations! ⇒ Array<DataMiner::Run>
Note:
Used extensively in github.com/brighterplanet/earth
Run the data miner scripts of parent associations. Useful for dependencies. Safe to call using process
.
49 50 51 52 53 54 55 |
# File 'lib/data_miner/active_record_class_methods.rb', line 49 def run_data_miner_on_parent_associations! reflect_on_all_associations(:belongs_to).reject do |assoc| assoc.[:polymorphic] end.map do |non_polymorphic_belongs_to_assoc| non_polymorphic_belongs_to_assoc.klass.run_data_miner! end end |