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_script ⇒ DataMiner::Script
Access this model’s script.
-
#run_data_miner! ⇒ Object
Run this model’s script.
-
#run_data_miner_on_parent_associations! ⇒ Object
Run the data miner scripts of parent associations.
Instance Method Details
#data_miner(options = {}) { ... } ⇒ nil
Define a data miner script.
93 94 95 96 97 98 99 100 |
# File 'lib/data_miner/active_record_class_methods.rb', line 93 def data_miner( = {}, &blk) = .stringify_keys unless ['append'] @data_miner_script = nil end data_miner_script.append_block blk nil 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! ⇒ Object
Run this model’s script.
18 19 20 |
# File 'lib/data_miner/active_record_class_methods.rb', line 18 def run_data_miner! data_miner_script.start end |
#run_data_miner_on_parent_associations! ⇒ Object
Note:
Used extensively in github.com/brighterplanet/earth
Run the data miner scripts of parent associations. Useful for dependencies. Safe to call using process
.
42 43 44 45 46 47 48 49 |
# File 'lib/data_miner/active_record_class_methods.rb', line 42 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 nil end |