lib/card/virtual.rb in card-mod-virtual-0.11.4 vs lib/card/virtual.rb in card-mod-virtual-0.11.5

- old
+ new

@@ -12,15 +12,14 @@ class << self def create card, virtual_content=nil validate_card card virtual_content ||= block_given? ? yield : card.generate_virtual_content - virtual = new left_id: left_id(card), right_id: right_id(card), - left_key: card.name.left_key, - content: virtual_content - virtual.save! - virtual + create! left_id: left_id(card), + right_id: right_id(card), + left_key: card.name.left_key, + content: virtual_content end def create_or_update card, virtual_content if (virtual_card = find_by_card(card)) virtual_card.update virtual_content @@ -38,10 +37,11 @@ end def refresh card virtual = find_by_card(card) return create(card) unless virtual + virtual.update card.generate_virtual_content end def find_content_by_card card where_card(card)&.pluck(:content)&.first @@ -62,33 +62,34 @@ end where query end def left_id card - if card.junction? + if card.compound? card.left_id&.positive? ? card.left_id : card.left&.id else card.id end end def right_id card - if card.junction? + if card.compound? card.right_id&.positive? ? card.right_id : card.right&.id else -2 end end def validate_card card reason ||= - if card.junction? + if card.compound? "needs left_id" unless left_id(card) "needs right_id" unless right_id(card) elsif !card.id "needs id" end return unless reason + raise Card::Error, card.name, "count not cacheable: card #{card.name} #{reason}" end end end end