Class | Membership
In: | lib/membership.rb
Parent: | Object

所属関係の変更に応じて `GrantOn` と `Permission` の同期を 行うための Observer を実装している。

### Methods

after_create after_destroy after_update new

### Constants

PRIORITIES | = | [ :PRIORITY_PERSON, :PRIORITY_GROUP, :PRIORITY_ORGANIZATION, :PRIORITY_COMPANY, :PRIORITY_DOMAIN, :PRIORITY_SENTINEL, ].freeze

### Public Class methods

new(name, priority)

[Source]

        # File lib/membership.rb, line 17
    17:   def initialize(name, priority)
    18:     @name = name
    19:     @priority = priority
    20:   end

### Public Instance methods

after_create(record)

[Source]

        # File lib/membership.rb, line 22
    22:   def after_create(record)
    23:     after_destroy(record) do |grant_on|
    24:       Permission.create(:grant_on_id => grant_on.id,
    25:                         :user_id => record.person.user.id,
    26:                         :priority => @priority,
    27:                         :grant_targettable_id => grant_on.grant_targettable_id,
    28:                         :grant_targettable_type => grant_on.grant_targettable_type,
    29:                         :value => grant_on.value,
    30:                         :start => [record.start, grant_on.start].max,
    31:                         :expiry => [record.expiry, grant_on.expiry].min)
    32:     end
    33:   end

after_destroy(record) {|grant_on if block_given?| ...}

[Source]

        # File lib/membership.rb, line 37
    37:   def after_destroy(record)
    38:     roleable_id = record.__send__ "#{@name}_id"
    39:     c = {:roleable_id => roleable_id, :roleable_type => @name.to_s.classify}
    40:     GrantOn.find_with_period(:all, :conditions => c).each do |grant_on|
    41:       Permission.find_with_period(:all, :conditions => "grant_on_id = '#{grant_on.id}'").each {|x| x.destroy}
    42:       yield grant_on if block_given?
    43:     end
    44:   end

after_update(record)

Alias for after_create

[Validate]