Sha256: e633ff5b1e1986ede83d208ccd4f71d5d44aefd0aefa3b3a3079bb384c8abf3c

Contents?: true

Size: 1.79 KB

Versions: 11

Compression:

Stored size: 1.79 KB

Contents

module SocialNetworking
  # A set of data representing a Social Profile belonging to a Participant.
  class Profile < ActiveRecord::Base
    ACTION_TYPES = %w( created completed )
    Actions = Struct.new(*ACTION_TYPES.map(&:to_sym)).new(*ACTION_TYPES)

    after_create :share_profile

    belongs_to :participant
    has_many :profile_answers,
             class_name: "SocialNetworking::ProfileAnswer",
             foreign_key: :social_networking_profile_id,
             dependent: :destroy
    has_many :comments, as: "item"
    has_many :likes, as: "item"

    validates :participant, presence: true
    validates :participant_id, uniqueness: true

    delegate :latest_action_at, :active_membership_end_date,
             to: :participant

    def self.icon_names
      %w(
        art
        bike
        bolt
        bookshelf
        die
        fashion
        flower
        genius
        heart
        helicopter
        hourglass
        keyboard
        magnifyingglass
        megaphone2
        microphone
        music
        paintbrush2
        plane
        polaroidcamera
        present
        recycle
        scooter
        shipwheel
        shoeprints
        star
        travelerbag
        ufo
        umbrella
        weather)
    end

    def to_serialized
      {}
    end

    def started?
      profile_answers.any?
    end

    def description
      "Welcome, #{user_name}!"
    end

    def shared_description
      "Profile Created: #{participant.display_name}"
    end

    def user_name
      if participant.is_admin
        Rails.application.config.moderating_participant_display_name
      else
        participant.display_name
      end
    end

    private

    def share_profile
      SharedItem.create(
        item: self,
        action_type: Profile::Actions.created)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
social_networking-0.11.8 app/models/social_networking/profile.rb
social_networking-0.11.7 app/models/social_networking/profile.rb
social_networking-0.11.6 app/models/social_networking/profile.rb
social_networking-0.11.5 app/models/social_networking/profile.rb
social_networking-0.11.4 app/models/social_networking/profile.rb
social_networking-0.11.3 app/models/social_networking/profile.rb
social_networking-0.11.2 app/models/social_networking/profile.rb
social_networking-0.11.1 app/models/social_networking/profile.rb
social_networking-0.11.0 app/models/social_networking/profile.rb
social_networking-0.10.0 app/models/social_networking/profile.rb
social_networking-0.9.3 app/models/social_networking/profile.rb