Class: Organizations::CallbackContext

Inherits:
Struct
  • Object
show all
Defined in:
lib/organizations/callback_context.rb

Overview

Immutable context object passed to all callbacks. Provides consistent, typed access to event data.

Different events populate different fields:

  • :organization_created => organization, user
  • :member_invited => organization, invitation, invited_by
  • :member_joined => organization, membership, user
  • :member_removed => organization, membership, user, removed_by
  • :role_changed => organization, membership, old_role, new_role, changed_by
  • :ownership_transferred => organization, old_owner, new_owner
  • :member_joining => organization, user, role, joined_via, invitation/join_request (whichever instrument applies) (STRICT + pre-persist: raise Organizations::MembershipVetoed to veto — see Configuration#on_member_joining)
  • :join_request_created => organization, user, join_request
  • :join_request_approved => organization, user, join_request, membership, decided_by (nil for auto-approvals)
  • :join_request_rejected => organization, user, join_request, decided_by

Examples:

Accessing context data

config.on_organization_created do |ctx|
  Analytics.track(ctx.user, "org_created", name: ctx.organization.name)
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#changed_byObject

Returns the value of attribute changed_by

Returns:

  • (Object)

    the current value of changed_by



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def changed_by
  @changed_by
end

#decided_byObject

Returns the value of attribute decided_by

Returns:

  • (Object)

    the current value of decided_by



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def decided_by
  @decided_by
end

#eventObject

Returns the value of attribute event

Returns:

  • (Object)

    the current value of event



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def event
  @event
end

#invitationObject

Returns the value of attribute invitation

Returns:

  • (Object)

    the current value of invitation



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def invitation
  @invitation
end

#invited_byObject

Returns the value of attribute invited_by

Returns:

  • (Object)

    the current value of invited_by



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def invited_by
  @invited_by
end

#join_requestObject

Returns the value of attribute join_request

Returns:

  • (Object)

    the current value of join_request



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def join_request
  @join_request
end

#joined_viaObject

Returns the value of attribute joined_via

Returns:

  • (Object)

    the current value of joined_via



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def joined_via
  @joined_via
end

#membershipObject

Returns the value of attribute membership

Returns:

  • (Object)

    the current value of membership



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def membership
  @membership
end

#metadataObject

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def 
  @metadata
end

#new_ownerObject

Returns the value of attribute new_owner

Returns:

  • (Object)

    the current value of new_owner



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def new_owner
  @new_owner
end

#new_roleObject

Returns the value of attribute new_role

Returns:

  • (Object)

    the current value of new_role



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def new_role
  @new_role
end

#old_ownerObject

Returns the value of attribute old_owner

Returns:

  • (Object)

    the current value of old_owner



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def old_owner
  @old_owner
end

#old_roleObject

Returns the value of attribute old_role

Returns:

  • (Object)

    the current value of old_role



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def old_role
  @old_role
end

#organizationObject

Returns the value of attribute organization

Returns:

  • (Object)

    the current value of organization



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def organization
  @organization
end

#permissionObject

Returns the value of attribute permission

Returns:

  • (Object)

    the current value of permission



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def permission
  @permission
end

#removed_byObject

Returns the value of attribute removed_by

Returns:

  • (Object)

    the current value of removed_by



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def removed_by
  @removed_by
end

#required_roleObject

Returns the value of attribute required_role

Returns:

  • (Object)

    the current value of required_role



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def required_role
  @required_role
end

#roleObject

Returns the value of attribute role

Returns:

  • (Object)

    the current value of role



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def role
  @role
end

#userObject

Returns the value of attribute user

Returns:

  • (Object)

    the current value of user



25
26
27
# File 'lib/organizations/callback_context.rb', line 25

def user
  @user
end

Instance Method Details

#event?(event_name) ⇒ Boolean

Check if this is a specific event type

Parameters:

  • event_name (Symbol)

    Event to check

Returns:

  • (Boolean)


56
57
58
# File 'lib/organizations/callback_context.rb', line 56

def event?(event_name)
  event == event_name
end

#to_hHash

Convert to hash, removing nil values

Returns:

  • (Hash)


49
50
51
# File 'lib/organizations/callback_context.rb', line 49

def to_h
  super.compact
end