Class: Stance::Events

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::Callbacks
Defined in:
lib/stance/events.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ Events

Returns a new instance of Events.



38
39
40
# File 'lib/stance/events.rb', line 38

def initialize(event)
  @event = event
end

Class Attribute Details

.eventsObject

Returns the value of attribute events.



12
13
14
# File 'lib/stance/events.rb', line 12

def events
  @events
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



7
8
9
# File 'lib/stance/events.rb', line 7

def event
  @event
end

Class Method Details

.after_create(*methods, &block) ⇒ Object



33
34
35
# File 'lib/stance/events.rb', line 33

def after_create(*methods, &block)
  set_callback :create, :after, *methods, &block
end

.before_create(*methods, &block) ⇒ Object



29
30
31
# File 'lib/stance/events.rb', line 29

def before_create(*methods, &block)
  set_callback :create, :before, *methods, &block
end

.event(name, options = {}) ⇒ Object

Raises:



20
21
22
23
24
25
26
27
# File 'lib/stance/events.rb', line 20

def event(name, options = {})
  @events ||= {}
  sname = name.to_s

  raise DuplicateEvent, "Cannot redefine event :#{sname} on #{self}" if @events.key?(sname)

  @events[sname] = options
end

.inherited(child) ⇒ Object



14
15
16
17
18
# File 'lib/stance/events.rb', line 14

def inherited(child)
  @events ||= {}
  child.events ||= @events.dup
  super
end