Class: Stance::Events
- Inherits:
-
Object
- Object
- Stance::Events
- Includes:
- ActiveSupport::Callbacks
- Defined in:
- lib/stance/events.rb
Class Attribute Summary collapse
-
.events ⇒ Object
Returns the value of attribute events.
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
Class Method Summary collapse
- .after_create(*methods, &block) ⇒ Object
- .before_create(*methods, &block) ⇒ Object
- .event(name, options = {}) ⇒ Object
- .inherited(child) ⇒ Object
Instance Method Summary collapse
-
#initialize(event) ⇒ Events
constructor
A new instance of Events.
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
.events ⇒ Object
Returns the value of attribute events.
12 13 14 |
# File 'lib/stance/events.rb', line 12 def events @events end |
Instance Attribute Details
#event ⇒ Object (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
20 21 22 23 24 25 26 27 |
# File 'lib/stance/events.rb', line 20 def event(name, = {}) @events ||= {} sname = name.to_s raise DuplicateEvent, "Cannot redefine event :#{sname} on #{self}" if @events.key?(sname) @events[sname] = 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 |