Class: MagicUserstamp::Event
- Inherits:
-
Object
- Object
- MagicUserstamp::Event
- Defined in:
- lib/magic_userstamp/event.rb
Instance Attribute Summary collapse
-
#actor ⇒ Object
readonly
Returns the value of attribute actor.
-
#actual_hook ⇒ Object
readonly
Returns the value of attribute actual_hook.
-
#after_callback ⇒ Object
readonly
Returns the value of attribute after_callback.
-
#default_attribute ⇒ Object
readonly
Returns the value of attribute default_attribute.
-
#default_attribute_compatible ⇒ Object
readonly
Returns the value of attribute default_attribute_compatible.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .[](event_name) ⇒ Object
- .actor_name(event_name) ⇒ Object
- .create(name, actor, default_attribute_compatible, options = nil, &block) ⇒ Object
- .each(&block) ⇒ Object
- .raise_unless_valid_name(event_name) ⇒ Object
- .valid_name?(event_name) ⇒ Boolean
- .valid_names ⇒ Object
Instance Method Summary collapse
-
#initialize(name, actor, default_attribute_compatible, options = nil) ⇒ Event
constructor
A new instance of Event.
Constructor Details
#initialize(name, actor, default_attribute_compatible, options = nil) ⇒ Event
Returns a new instance of Event.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/magic_userstamp/event.rb', line 10 def initialize(name, actor, default_attribute_compatible, = nil) @name, @actor = name.to_s, actor.to_s @default_attribute = "#{@actor}_id" @default_attribute_compatible = default_attribute_compatible = { :actual_hook => "before_#{@name.to_s}" }.update( || {}) @actual_hook = [:actual_hook] @after_callback = [:after_callback] end |
Instance Attribute Details
#actor ⇒ Object (readonly)
Returns the value of attribute actor.
7 8 9 |
# File 'lib/magic_userstamp/event.rb', line 7 def actor @actor end |
#actual_hook ⇒ Object (readonly)
Returns the value of attribute actual_hook.
7 8 9 |
# File 'lib/magic_userstamp/event.rb', line 7 def actual_hook @actual_hook end |
#after_callback ⇒ Object (readonly)
Returns the value of attribute after_callback.
7 8 9 |
# File 'lib/magic_userstamp/event.rb', line 7 def after_callback @after_callback end |
#default_attribute ⇒ Object (readonly)
Returns the value of attribute default_attribute.
8 9 10 |
# File 'lib/magic_userstamp/event.rb', line 8 def default_attribute @default_attribute end |
#default_attribute_compatible ⇒ Object (readonly)
Returns the value of attribute default_attribute_compatible.
8 9 10 |
# File 'lib/magic_userstamp/event.rb', line 8 def default_attribute_compatible @default_attribute_compatible end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/magic_userstamp/event.rb', line 7 def name @name end |
Class Method Details
.[](event_name) ⇒ Object
31 32 33 34 |
# File 'lib/magic_userstamp/event.rb', line 31 def [](event_name) raise_unless_valid_name(event_name) @name_hash[event_name] end |
.actor_name(event_name) ⇒ Object
41 42 43 |
# File 'lib/magic_userstamp/event.rb', line 41 def actor_name(event_name) self[event_name].actor end |
.create(name, actor, default_attribute_compatible, options = nil, &block) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/magic_userstamp/event.rb', line 22 def create(name, actor, default_attribute_compatible, = nil, &block) result = self.new(name, actor, default_attribute_compatible, , &block) @name_hash ||= HashWithIndifferentAccess.new @name_hash[name] = result @instances ||= [] @instances << result result end |
.each(&block) ⇒ Object
36 37 38 39 |
# File 'lib/magic_userstamp/event.rb', line 36 def each(&block) return unless block (@instances || []).each(&block) end |
.raise_unless_valid_name(event_name) ⇒ Object
53 54 55 56 |
# File 'lib/magic_userstamp/event.rb', line 53 def raise_unless_valid_name(event_name) return if valid_name?(event_name) raise MagicUserstampError, "Invalid event name '#{event_name.inspect}'. Event name must be one of #{valid_names.inspect}" end |
.valid_name?(event_name) ⇒ Boolean
49 50 51 |
# File 'lib/magic_userstamp/event.rb', line 49 def valid_name?(event_name) valid_names.include?(event_name.to_s) end |
.valid_names ⇒ Object
45 46 47 |
# File 'lib/magic_userstamp/event.rb', line 45 def valid_names (@instances || []).map(&:name) end |