Module: BrighterPlanet::Emitter
- Defined in:
- lib/emitter.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- REQUIRED_COMPONENTS =
%w{ impact_model characterization data relationships summarization }
Class Method Summary collapse
Instance Method Summary collapse
-
#included(base) ⇒ Object
“included” not “self.included” why? This module **extends other modules** it forcibly (over)writes their definitions of self.included BrighterPlanet::AutomobileTrip.extend(Emitter) -> now BrighterPlanet::AutomobileTrip has self.included MyAutomobileTrip.include(BrighterPlanet::AutomobileTrip) -> will call BrighterPlanet::AutomobileTrip.included(MyAutomobileTrip).
-
#scope(statement) ⇒ Object
this gets added as a class method to the emitter module.
Class Method Details
.extended(target) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/emitter.rb', line 21 def self.extended(target) common_name = target.name.demodulize.underscore REQUIRED_COMPONENTS.each do |component| require "#{common_name}/#{component}" end end |
Instance Method Details
#included(base) ⇒ Object
“included” not “self.included” why? This module **extends other modules** it forcibly (over)writes their definitions of self.included BrighterPlanet::AutomobileTrip.extend(Emitter) -> now BrighterPlanet::AutomobileTrip has self.included MyAutomobileTrip.include(BrighterPlanet::AutomobileTrip) -> will call BrighterPlanet::AutomobileTrip.included(MyAutomobileTrip)
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/emitter.rb', line 34 def included(base) base.extend ClassMethods # here self is the emitter module common_name = self.name.demodulize.underscore common_camel = common_name.camelcase base.instance_variable_set :@impact_scope, @impact_scope if @impact_scope base.extend ::Leap::Subject base.send :include, "::BrighterPlanet::#{common_camel}::ImpactModel".constantize base.send :include, ::Charisma base.send :include, "::BrighterPlanet::#{common_camel}::Characterization".constantize base.class_eval do preexisting = characterization.keys decisions[:impact].committees.reject do |committee| preexisting.include?(committee.name) end.each do |committee| characterize do has committee.name, :options => committee..slice(:measures, :display_with) end end end base.send :include, "::BrighterPlanet::#{common_camel}::Data".constantize base.data_miner_script.prepend_once :process, :auto_upgrade! base.data_miner_script.append_once :process, :run_data_miner_on_parent_associations! base.extend ::SummaryJudgement base.send :include, "::BrighterPlanet::#{common_camel}::Summarization".constantize begin require "#{common_name}/fallback" base.send :include, "::BrighterPlanet::#{common_camel}::Fallback".constantize rescue ::LoadError # not required end base.send :include, "::BrighterPlanet::#{common_camel}::Relationships".constantize end |
#scope(statement) ⇒ Object
this gets added as a class method to the emitter module
78 79 80 |
# File 'lib/emitter.rb', line 78 def scope(statement) @impact_scope = statement end |