class CyberCoach::Partnership

A Partnership consists of two Users, which participate in different Sport with Subscriptions, to which Entries are submitted.

Attributes

confirmed_by_proposed[RW]

True if the proposed User has confirmed it, false otherwise.

confirmed_by_proposer[RW]

True if the proposing User has confirmed it, false otherwise.

privacy_level[RW]

:attr: privacy_level The privacy level, see PrivacyLevel constants.

proposed[RW]

The User it is proposed to.

proposer[RW]

The User who proposed it.

subscriptions[RW]

The Subscriptions.

Protected Instance Methods

initializable_with() click to toggle source
Calls superclass method
# File lib/cybercoach/partnership.rb, line 151
def initializable_with
  super + [:proposer, :proposed, :privacy_level]
end

Configuration

↑ top

Public Instance Methods

plural_name() click to toggle source

Returns ‘partnerships’.

# File lib/cybercoach/partnership.rb, line 133
def plural_name
  'partnerships'
end
singular_name() click to toggle source

Returns ‘partnership’.

# File lib/cybercoach/partnership.rb, line 124
def singular_name
  'partnership'
end

Invalidation

↑ top

Protected Instance Methods

invalidate_uri() click to toggle source

Sets the uri to the base uri and the proposer’s and proposed’s username if neither of them is nil.

# File lib/cybercoach/partnership.rb, line 145
def invalidate_uri
  unless @proposer.nil? || @proposed.nil?
    @uri = "#{resource_base_uri}#{@proposer.username};#{@proposed.username}/"
  end
end

Serialization

↑ top

Public Instance Methods

from_serializable(serializable) click to toggle source

Creates itself from a serializable representation, which only contains simple data types.

serializable

A hash with the keys:

  • uri

    The URI.

  • id

    The identifier.

  • user1

    A User serializable of the proposer.

  • user2

    A User serializable of the proposed.

  • subscriptions

    Subscription serializables.

  • userconfirmed1

    True if the proposing User has confirmed it, false otherwise.

  • userconfirmed2

    True if the proposed User has confirmed it, false otherwise.

  • publicvisible

    The privacy level, see PrivacyLevel constants.

Calls superclass method
# File lib/cybercoach/partnership.rb, line 69
def from_serializable(serializable)
  super(serializable)
  @proposer = nil
  unless serializable['user1'].nil?
    @proposer = User.new
    @proposer.from_serializable(serializable['user1'])
  end
  @proposed = nil
  unless serializable['user2'].nil?
    @proposed = User.new
    @proposed.from_serializable(serializable['user2'])
  end
  @subscriptions = []
  unless serializable['subscriptions'].nil?
    @subscriptions = serializable['subscriptions'].map do
    |subscription_serializable|
      subscription = Subscription.new
      subscription.from_serializable(subscription_serializable)
      subscription
    end
  end
  @confirmed_by_proposer = serializable['userconfirmed1']
  @confirmed_by_proposed = serializable['userconfirmed2']
  @privacy_level = serializable['publicvisible']
end
to_serializable() click to toggle source

Returns a serializable representation, which only contains simple data types. The hash has the keys:

  • uri

    The URI.

  • id

    The identifier.

  • user1

    A User serializable of the proposer.

  • user2

    A User serializable of the proposed.

  • publicvisible

    The privacy level, see PrivacyLevel constants.

Calls superclass method
# File lib/cybercoach/partnership.rb, line 107
def to_serializable
  serializable = super
  unless @proposer.nil?
    serializable['user1'] = @proposer.to_serializable
  end
  unless @proposed.nil?
    serializable['user2'] = @proposed.to_serializable
  end
  serializable['publicvisible'] = @privacy_level
  serializable
end