Sha256: f61b0cbeb537700af6cd44d87cc2be363fa4988d8f8a04f9aeaec3b7d59c7bb4

Contents?: true

Size: 1.01 KB

Versions: 55

Compression:

Stored size: 1.01 KB

Contents

# A collection of Activities that have not been scheduled by a Participant.
class UnplannedActivities
  Errors = Struct.new(:full_messages)

  attr_reader :errors

  def self.attribute_names
    []
  end

  def initialize(participant)
    @participant = participant
    @activities = []
  end

  def build(attributes)
    many_attributes = case
                      when attributes[:activity_type_ids]
                        (attributes[:activity_type_ids] || []).map do |type_id|
                          { activity_type_id: type_id }
                        end
                      else
                        attributes.values
                      end
    build_many(many_attributes)

    self
  end

  def save
    Activity.transaction { @activities.each(&:save!) }

    true
  rescue => err
    @errors = Errors.new(Array(err.to_s))

    false
  end

  private

  def build_many(arr_of_attributes)
    arr_of_attributes.each do |attrs|
      @activities << @participant.build_data_record(:activities, attrs)
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
think_feel_do_engine-3.19.9 app/models/unplanned_activities.rb
think_feel_do_engine-3.19.8 app/models/unplanned_activities.rb
think_feel_do_engine-3.19.7 app/models/unplanned_activities.rb
think_feel_do_engine-3.19.6 app/models/unplanned_activities.rb
think_feel_do_engine-3.19.5 app/models/unplanned_activities.rb
think_feel_do_engine-3.19.4 app/models/unplanned_activities.rb
think_feel_do_engine-3.19.3 app/models/unplanned_activities.rb
think_feel_do_engine-3.19.2 app/models/unplanned_activities.rb
think_feel_do_engine-3.19.1 app/models/unplanned_activities.rb
think_feel_do_engine-3.19.0 app/models/unplanned_activities.rb
think_feel_do_engine-3.18.0 app/models/unplanned_activities.rb
think_feel_do_engine-3.17.2 app/models/unplanned_activities.rb
think_feel_do_engine-3.17.1 app/models/unplanned_activities.rb
think_feel_do_engine-3.17.0 app/models/unplanned_activities.rb
think_feel_do_engine-3.16.3 app/models/unplanned_activities.rb
think_feel_do_engine-3.16.2 app/models/unplanned_activities.rb
think_feel_do_engine-3.16.1 app/models/unplanned_activities.rb
think_feel_do_engine-3.15.7 app/models/unplanned_activities.rb
think_feel_do_engine-3.16.0 app/models/unplanned_activities.rb
think_feel_do_engine-3.15.6 app/models/unplanned_activities.rb