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.15.5 app/models/unplanned_activities.rb
think_feel_do_engine-3.15.4 app/models/unplanned_activities.rb
think_feel_do_engine-3.15.3 app/models/unplanned_activities.rb
think_feel_do_engine-3.15.2 app/models/unplanned_activities.rb
think_feel_do_engine-3.15.1 app/models/unplanned_activities.rb
think_feel_do_engine-3.15.0 app/models/unplanned_activities.rb
think_feel_do_engine-3.14.9 app/models/unplanned_activities.rb
think_feel_do_engine-3.14.8 app/models/unplanned_activities.rb
think_feel_do_engine-3.14.7 app/models/unplanned_activities.rb
think_feel_do_engine-3.14.6 app/models/unplanned_activities.rb
think_feel_do_engine-3.14.5 app/models/unplanned_activities.rb
think_feel_do_engine-3.14.4 app/models/unplanned_activities.rb
think_feel_do_engine-3.14.3 app/models/unplanned_activities.rb
think_feel_do_engine-3.14.2 app/models/unplanned_activities.rb
think_feel_do_engine-3.14.1 app/models/unplanned_activities.rb
think_feel_do_engine-3.14.0 app/models/unplanned_activities.rb
think_feel_do_engine-3.13.1 app/models/unplanned_activities.rb
think_feel_do_engine-3.13.0 app/models/unplanned_activities.rb
think_feel_do_engine-3.12.9 app/models/unplanned_activities.rb
think_feel_do_engine-3.12.8 app/models/unplanned_activities.rb