Class: Pretentious::LazyTrigger
- Inherits:
-
Object
- Object
- Pretentious::LazyTrigger
- Defined in:
- lib/pretentious/lazy_trigger.rb
Defined Under Namespace
Classes: Target
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#target_class ⇒ Object
Returns the value of attribute target_class.
-
#targets ⇒ Object
Returns the value of attribute targets.
Class Method Summary collapse
- .clear ⇒ Object
- .collect_artifacts ⇒ Object
- .collect_targets ⇒ Object
- .lookup(class_name) ⇒ Object
- .register_instance(instance) ⇒ Object
- .unregister_instance(instance) ⇒ Object
Instance Method Summary collapse
- #disable! ⇒ Object
-
#initialize(target_class, options = {}) ⇒ LazyTrigger
constructor
A new instance of LazyTrigger.
- #register_class(module_space, klass, last_part, stand_in_class) ⇒ Object
- #restore ⇒ Object
Constructor Details
#initialize(target_class, options = {}) ⇒ LazyTrigger
Returns a new instance of LazyTrigger.
20 21 22 23 24 25 |
# File 'lib/pretentious/lazy_trigger.rb', line 20 def initialize(target_class, = {}) @target_class = target_class = @targets = {} Pretentious::LazyTrigger.register_instance(self) end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/pretentious/lazy_trigger.rb', line 3 def end |
#target_class ⇒ Object
Returns the value of attribute target_class.
3 4 5 |
# File 'lib/pretentious/lazy_trigger.rb', line 3 def target_class @target_class end |
#targets ⇒ Object
Returns the value of attribute targets.
3 4 5 |
# File 'lib/pretentious/lazy_trigger.rb', line 3 def targets @targets end |
Class Method Details
.clear ⇒ Object
71 72 73 |
# File 'lib/pretentious/lazy_trigger.rb', line 71 def clear @instances = [] end |
.collect_artifacts ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/pretentious/lazy_trigger.rb', line 61 def collect_artifacts artifacts = [] @instances.each do |instance| instance.targets.values.each do |target| artifacts << target.stand_in_klass end end artifacts end |
.collect_targets ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/pretentious/lazy_trigger.rb', line 51 def collect_targets artifacts = [] @instances.each do |instance| instance.targets.values.each do |target| artifacts << target end end artifacts end |
.lookup(class_name) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/pretentious/lazy_trigger.rb', line 43 def lookup(class_name) @instances ||= [] @instances.each do |instance| return instance if instance.target_class == class_name end nil end |
.register_instance(instance) ⇒ Object
75 76 77 78 |
# File 'lib/pretentious/lazy_trigger.rb', line 75 def register_instance(instance) @instances ||= [] @instances << instance unless @instances.include? instance end |
.unregister_instance(instance) ⇒ Object
80 81 82 |
# File 'lib/pretentious/lazy_trigger.rb', line 80 def unregister_instance(instance) @instances.delete(instance) end |
Instance Method Details
#disable! ⇒ Object
27 28 29 |
# File 'lib/pretentious/lazy_trigger.rb', line 27 def disable! Pretentious::LazyTrigger.unregister_instance(self) end |
#register_class(module_space, klass, last_part, stand_in_class) ⇒ Object
37 38 39 40 |
# File 'lib/pretentious/lazy_trigger.rb', line 37 def register_class(module_space, klass, last_part, stand_in_class) target = Pretentious::LazyTrigger::Target.new(module_space, klass, last_part, stand_in_class) @targets[target.stand_in_klass] = target unless @targets.include? target.stand_in_klass end |
#restore ⇒ Object
31 32 33 34 35 |
# File 'lib/pretentious/lazy_trigger.rb', line 31 def restore @targets.each do |_stand_in_klass, target| Pretentious::Generator.restore_class target.module_space, target.original_klass, target.name end end |