lib/troo/models/card.rb in troo-0.0.7 vs lib/troo/models/card.rb in troo-0.0.8

- old
+ new

@@ -22,45 +22,63 @@ index :external_list_id index :external_card_id alias_method :default?, :default + def self.remote(id, options = { mode: :card }) + External::Card.fetch(id, options).first + end + + def external_member_ids + if @attributes[:external_member_ids].nil? + [] + elsif @attributes[:external_member_ids].is_a?(Array) + @attributes[:external_member_ids] + else + JSON(@attributes[:external_member_ids]) + end + end + def board - BoardRetrieval.retrieve(self.external_board_id) + @board ||= Retrieval::Board.retrieve(external_board_id) end def list - ListRetrieval.retrieve(self.external_list_id) + @list ||= Retrieval::List.retrieve(external_list_id) end def comments - Troo::Comment.find(external_card_id: self.external_card_id) + Troo::Comment.find(external_card_id: 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 + return [] if external_member_ids.empty? + @members ||= external_member_ids.map do |member_id| + Retrieval::Member.retrieve(member_id) + end.compact end def decorator(options = {}) - CardDecorator.new(self, options) + Decorators::Card.new(self, options) end - def presenter - CardPresenter.new(self) + def presenter(options = {}) + Presenters::Card.new(self, options) end + def comment_presenter(options = {}) + Presenters::Comment.new(self, options) + end + + def member_presenter(options = {}) + Presenters::Member.new(self, options) + end + def set_default! - SetDefault.for(self) + Behaviours::SetDefault.for(self) end end end -