Sha256: c971baa1b5e33fd670ac660197cc7d881da9584ef0ce610da0fc5852d65884b7

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

module Troo
  class Card < Ohm::Model
    include Ohm::DataTypes
    include ModelHelpers

    attribute :short_id
    attribute :name
    attribute :desc
    attribute :url
    attribute :external_member_ids, Type::Array
    attribute :position
    attribute :last_activity_date
    attribute :default, Type::Boolean
    attribute :closed, Type::Boolean
    attribute :external_board_id
    attribute :external_list_id
    attribute :external_card_id

    index :short_id
    index :default
    index :external_board_id
    index :external_list_id
    index :external_card_id

    alias_method :default?, :default

    def board
      Troo::BoardRetrieval.retrieve(self.external_board_id)
    end

    def list
      Troo::ListRetrieval.retrieve(self.external_list_id)
    end

    def comments
      Troo::Comment.find(external_card_id: self.external_card_id)
    end

    def recent_comments
      comments.sort(by: :date, limit: [0, 3])
    end

    def members
      if external_member_ids.any?
        m = external_member_ids.map do |external_member_id|
          Troo::Member.first(external_member_id: external_member_id)
        end.compact
      else
        []
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
troo-0.0.4 lib/troo/models/card.rb
troo-0.0.3 lib/troo/models/card.rb
troo-0.0.2 lib/troo/models/card.rb