Class: Pretentious::LazyTrigger

Inherits:
Object
  • Object
show all
Defined in:
lib/pretentious/lazy_trigger.rb

Defined Under Namespace

Classes: Target

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  @target_class = target_class
  @options = options
  @targets = {}
  Pretentious::LazyTrigger.register_instance(self)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/pretentious/lazy_trigger.rb', line 3

def options
  @options
end

#target_classObject

Returns the value of attribute target_class.



3
4
5
# File 'lib/pretentious/lazy_trigger.rb', line 3

def target_class
  @target_class
end

#targetsObject

Returns the value of attribute targets.



3
4
5
# File 'lib/pretentious/lazy_trigger.rb', line 3

def targets
  @targets
end

Class Method Details

.clearObject



71
72
73
# File 'lib/pretentious/lazy_trigger.rb', line 71

def clear
  @instances = []
end

.collect_artifactsObject



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_targetsObject



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

#restoreObject



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