Module: PreAction::Methods

Defined in:
lib/pre_action.rb

Instance Method Summary collapse

Instance Method Details

#method_added(method) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pre_action.rb', line 15

def method_added method
	return unless @actions
	return if @actions.empty?
	return unless @actions.include? method
	return if @updated_action[method]

	method_impl = instance_method(method)

	method_fork = %Q{
		define_method :#{method.to_s} do
			self.#{@pre_action}
			method_impl.bind(self).call
		end
	}
	@updated_action[method] = true

	self.class_eval(method_fork)
end

#pre_action(pre_action_name, action_names) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/pre_action.rb', line 7

def pre_action pre_action_name, action_names
	raise 'no actions for running pre-action' unless action_names.has_key?(:for)
	@actions = action_names[:for]
	@pre_action = pre_action_name
	@updated_action = {}
	@actions.each{|a| @updated_action[a] = false}
end