Method: FruitToLime::RootModel#add_deal

Defined in:
lib/fruit_to_lime/model/rootmodel.rb

#add_deal(deal) ⇒ Object

Adds the specifed deal object to the model. care about duplicates not being added. Your model might not be saved due to duplicate integration_ids.

begin
   rootmodel.add_deal(deal)
rescue FruitToLime::AlreadyAddedError
   puts "Warning: already added deal"
end

Examples:

Add an deal from a hash

rootmodel.add_deal({
    :integration_id => "123",
    :name => "Big deal",
})

Add a deal from a new deal

deal = FruitToLime::Deal.new
deal.integration_id = "123"
deal.name = "Big deal"
rootmodel.add_deal(deal)

If you want to keep adding deals and dont

See Also:



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/fruit_to_lime/model/rootmodel.rb', line 147

def add_deal(deal)
    @deals = [] if @deals.nil?

    if deal.nil?
        return nil
    end

    deal = Deal.new(deal) if !deal.is_a?(Deal)

    if find_deal_by_integration_id(deal.integration_id) != nil
        raise AlreadyAddedError, "Already added a deal with integration_id #{deal.integration_id}"
    end

    if deal.responsible_coworker.nil?
        deal.responsible_coworker = @import_coworker
    end

    @deals.push(deal)

    return deal
end