Module: Hyperactive::Hooker::Pimp

Defined in:
lib/hyperactive/hooker.rb

Overview

Something that uses hooks a lot, include if you want support for various types of hooks.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.append_features(base) ⇒ Object

Upon inclusion, our base class will be given a set of hook arrays, and then get extended by ClassMethods.



35
36
37
38
39
40
41
42
# File 'lib/hyperactive/hooker.rb', line 35

def self.append_features(base)
  super
  base.instance_variable_set(:@create_hooks, [])
  base.instance_variable_set(:@destroy_hooks, [])
  base.instance_variable_set(:@save_hooks, [])
  base.instance_variable_set(:@load_hooks, [])
  base.extend(ClassMethods)
end

Instance Method Details

#load_hook(&block) ⇒ Object

This will allow us to wrap any load of us from persistent storage in the @@load_hooks as long as the Archipelago::Hashish provider supports it. See Archipelago::Hashish::BerkeleyHashish for an example of Hashish providers that do this.



62
63
64
65
66
# File 'lib/hyperactive/hooker.rb', line 62

def load_hook(&block)
  self.class.with_hooks(:instance => self, :hooks => self.class.load_hooks) do
    yield
  end
end

#save_hook(old_value, &block) ⇒ Object

This will allow us to wrap any write of us to persistent storage in the @save_hooks as long as the Archipelago::Hashish provider supports it. See Archipelago::Hashish::BerkeleyHashish for an example of Hashish providers that do this.



50
51
52
53
54
# File 'lib/hyperactive/hooker.rb', line 50

def save_hook(old_value, &block)
  self.class.with_hooks(:instance => self, :arguments => [old_value], :hooks => self.class.save_hooks) do
    yield
  end
end